How to change the switch component's size in React Native?
<Switch onValueChange={this._changeReciveNotice.bind(this)}
value={this.state.isReciveNotice}
style={{width:20,height:10}}/>
this style code doesn't effect
The different Switch sizes available are default and small. To reduce the size of default Switch to small, set the cssClass property to e-small .
To set width style to a percentage number with React Native, we can use flexbox. to set flexDirection to 'row' to add a horizontal flexbox layout. We set the 2nd Text component to fill 20% of the screen. Then we set flexGrow to 1 on the first Text component to expand to fill the remaining width of the screen.
You can resize the switch by using transform property from styling,
<Switch value={true}
style={{ transform: [{ scaleX: .8 }, { scaleY: .8 }] }}
onValueChange={(value) => {}} />
also for best result determine scaling values based on screen dimension.
To expand on what was already said, this is how you can handle screen sizes:
import { moderateScale } from 'react-native-size-matters';
...
<Switch
style={{ transform: [{ scaleX: moderateScale(1, 0.2) }, { scaleY:
moderateScale(1, 0.2) }] }} />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With