peacechen / react-native-modal-selector

A cross-platform (iOS / Android), selector/picker component for React Native that is highly customizable and supports sections.
MIT License
369 stars 129 forks source link

Pass font scaling props to <Text/> children? #129

Closed enaluz closed 4 years ago

enaluz commented 4 years ago

I recently had to go into my app and add better styling support for devices with varying font scaling. Typically this is done with props applied to the <Text/> component like maxFontSizeMultiplier and allowFontScaling. Although I could supply custom components to the <ModalSelector/> component, it would be great if I could just pass down the necessary props directly to the <Text/> component.

Is there already a way to do this that I'm missing? Would appreciate everyone's thoughts on this.

enaluz commented 4 years ago

I made a very simple patch for myself to use this feature now-- it involved adding maxFontSizeMultiplier={this.props.maxFontSizeMultiplier || 2} to the 4 <Text/> components, and adding maxFontSizeMultiplier?: number to the types file. 2 might not be the optimal default value, but was good enough for my use case. Happy to make a PR if we agree on this implementation.

peacechen commented 4 years ago

Thanks for noting this and sharing your solution. A PR would be welcome.

I would recommend adding a prop object that passes through to the Text components. While you need it for allowFontScaling presently, someone down the road may want to insert another prop. That seems to be the most flexible approach.

Currently there are optionTextPassThruProps and selectTextPassThruProps for some of the Text elements. You could add new props to the others in the same fashion.

tetianastepova commented 4 years ago

I pushed PR with the changes that you've discussed... You can find it here, could you please take a look

peacechen commented 4 years ago

Thanks @tetianastepova for the PR.

This feature has been published in 2.0.3