Skip to content

Commit b048d4c

Browse files
committed
Fix iOS TextInput Dynamic Type audit support
1 parent c65845c commit b048d4c

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
2424
@property (nonatomic, weak, nullable) id<RCTBackedTextInputDelegate> textInputDelegate;
2525
@property (nonatomic, readonly) CGSize contentSize;
2626
@property (nonatomic, strong, nullable) NSDictionary<NSAttributedStringKey, id> *defaultTextAttributes;
27+
@property (nonatomic, assign) BOOL adjustsFontForContentSizeCategory;
2728
@property (nonatomic, assign) BOOL contextMenuHidden;
2829
@property (nonatomic, assign, getter=isEditable) BOOL editable;
2930
@property (nonatomic, assign) BOOL caretHidden;

packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ @interface RCTTextInputComponentView () <
4242

4343
static NSSet<NSNumber *> *returnKeyTypesSet;
4444

45+
static BOOL RCTAdjustsFontForContentSizeCategoryFromTextAttributes(const TextAttributes &textAttributes)
46+
{
47+
return textAttributes.allowFontScaling.value_or(true);
48+
}
49+
4550
@implementation RCTTextInputComponentView {
4651
TextInputShadowNode::ConcreteState::Shared _state;
4752
UIView<RCTBackedTextInputViewProtocol> *_backedTextInputView;
@@ -92,6 +97,8 @@ - (instancetype)initWithFrame:(CGRect)frame
9297

9398
_backedTextInputView = defaultProps->multiline ? [RCTUITextView new] : [RCTUITextField new];
9499
_backedTextInputView.textInputDelegate = self;
100+
_backedTextInputView.adjustsFontForContentSizeCategory =
101+
RCTAdjustsFontForContentSizeCategoryFromTextAttributes(defaultProps->textAttributes);
95102
_ignoreNextTextInputCall = NO;
96103
_comingFromJS = NO;
97104
_didMoveToWindow = NO;
@@ -145,6 +152,8 @@ - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
145152
const auto &newTextInputProps = static_cast<const TextInputProps &>(*_props);
146153
_backedTextInputView.defaultTextAttributes =
147154
RCTNSTextAttributesFromTextAttributes(newTextInputProps.getEffectiveTextAttributes(RCTFontSizeMultiplier()));
155+
_backedTextInputView.adjustsFontForContentSizeCategory =
156+
RCTAdjustsFontForContentSizeCategoryFromTextAttributes(newTextInputProps.textAttributes);
148157
}
149158
}
150159

@@ -298,6 +307,8 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
298307
defaultAttributes[RCTAttributedStringEventEmitterKey] =
299308
_backedTextInputView.defaultTextAttributes[RCTAttributedStringEventEmitterKey];
300309
_backedTextInputView.defaultTextAttributes = defaultAttributes;
310+
_backedTextInputView.adjustsFontForContentSizeCategory =
311+
RCTAdjustsFontForContentSizeCategoryFromTextAttributes(newTextInputProps.textAttributes);
301312
}
302313

303314
if (newTextInputProps.selectionColor != oldTextInputProps.selectionColor) {

packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void RCTCopyBackedTextInput(
3030
toTextInput.textInputDelegate = fromTextInput.textInputDelegate;
3131
toTextInput.placeholderColor = fromTextInput.placeholderColor;
3232
toTextInput.defaultTextAttributes = fromTextInput.defaultTextAttributes;
33+
toTextInput.adjustsFontForContentSizeCategory = fromTextInput.adjustsFontForContentSizeCategory;
3334
toTextInput.autocapitalizationType = fromTextInput.autocapitalizationType;
3435
toTextInput.autocorrectionType = fromTextInput.autocorrectionType;
3536
toTextInput.contextMenuHidden = fromTextInput.contextMenuHidden;

packages/rn-tester/js/examples/TextInput/TextInputExample.ios.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ const textInputExamples: Array<RNTesterModuleExample> = [
762762
/>
763763
<ExampleTextInput
764764
style={{marginTop: 10}}
765-
placeholder="allowFontScaling = false"
765+
placeholder="allowFontScaling = true"
766766
allowFontScaling={true}
767767
/>
768768
</View>

0 commit comments

Comments
 (0)