Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the switch component's size in React Native?

Tags:

react-native

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

like image 475
alucard.g Avatar asked Sep 21 '16 10:09

alucard.g


People also ask

How do you reduce the size of switch in React Native?

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 .

How do I change the width of a percentage in React Native?

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.


2 Answers

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.

like image 107
Eltaf Hussain Avatar answered Dec 18 '22 19:12

Eltaf Hussain


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) }] }} />
like image 33
TacoEater Avatar answered Dec 18 '22 17:12

TacoEater