M3 styled switch
Is your feature request related to a problem? Please describe.
get a m3 styled switch component
Describe the solution you'd like
just edit stylesheet
Additional context




@rollingmoai Are you trying it on iOS ? I tried it on Android and Web and Handle isn't having that bug.
I have changed it in handle too. Now try it out
@rollingmoai wait how?
Sorry, I forgot to mention. It happens when you disable it from an off state. But I guess it is fixed now.
@rollingmoai oh alr, well now about animation, instead of giving it as a animationSpeed:number we should give it as
animationSpeed:'normal'|'slow'|'slower'|'fast'|'faster'
So user can decide from predefined 5 animation speeds. This because the animation kinda breaks if you make it faster/slower than specific values. So instead keep constrains with 5 different animation types will be enough for customisation. What do you think ?
@rollingmoai Some animations were for icon of Switch in Material Design Guidelines. I added it to Switch : ( might appear little laggy due to screen recording ) :
https://github.com/callstack/react-native-paper/assets/150055488/52217ec8-6d87-4ea9-b930-c4de6d7bcf77
This one from material you website :
https://github.com/callstack/react-native-paper/assets/150055488/d855c11a-3661-4b19-b232-8b05719782e1
as you see the Icon kinda rotates and scales off.
I have only added it to Switch List Item Component, if you think we should keep this, then I can add it to Normal Switch Component. You can try it on snack.
@rollingmoai oh alr, well now about animation, instead of giving it as a
animationSpeed:numberwe should give it asanimationSpeed:'normal'|'slow'|'slower'|'fast'|'faster'So user can decide from predefined 5 animation speeds. This because the animation kinda breaks if you make it faster/slower than specific values. So instead keep constrains with 5 different animation types will be enough for customisation. What do you think ?
Makes sense yeah
@rollingmoai hey just found something funny, even Google's switch isn't perfect. Look if you swipe if too quick, it expands but isn't able to get to original size in that time.
https://github.com/callstack/react-native-paper/assets/150055488/134ad1c2-83e1-4c93-9a83-a2dca8a82ec4
@rollingmoai I will be quite busy for a few days, I will continue to work on Material switch after that.
Super glad y'all are working on this!! Thank you so much!
@rollingmoai The new Switch Component is ready, changes I did :
MaterialSwitchListItemonly shows fluid animation when clicked onListItem. When clicked on Switch, it shows normal animation. ( I did this because that's how Google's Switch work in Google File's App, only shows fluid animation when clicked onListItem)- Added
descriptionStyletoMaterialSwitchListItem. - Optimized fluid animation to be more smoother. ( before, It was smooth on my 8Gb RAM phone, but lagged on old 4GB RAM phone, but now it works smooth on both ).
Also one more thing, I think we shouldn't add animationTimeScaling prop. It adds complexity to animations due to conditional code. Rather I already changed animation a bit faster so it doesn't feel like waiting for it to complete.
I think the component is now usable. We can finalize this, what do you think ?
Here's the snack
Here's the snack
@rollingmoai One more thing about Snack, it's working fine on web, but in expo go app, there's a little problem ONLY when dragging the switch. It cancels touch if you move you finger little out of Switch. But it only happens in that Snack, I am using the Switch component in my app and it's working fine. Maybe it's happening due to ScrollView.
You can check how its working in my app's settings, here's download link, it's EAS built apk file, you can install and try it in your device. You will find Switch in Theme dialog of settings screen. And a there's group of Switches in Note Type Settings .
@yuameshi Hello there, you opened this issue, so I would like you to check this new Material Switch component. You can use it with React Native Paper.
@lukewalczak any reason this shouldn't be added to React Native Paper officially?
Hi @crystalarcus ,
Thanks for the amazing work on this.
Whats the update on this? Was this merged into React Native Paper officially?
Whats the update on this? Was this merged into React Native Paper officially?
@Santhosh-Umapathi It can't be directly merged into React Native Paper but I can make a npm package which u can install and directly use MaterialSwitch component with React Native Paper. Or if you need it urgently you can just copy the Switch Components files from snack
@yuameshi Hello there, you opened this issue, so I would like you to check this new Material Switch component. You can use it with React Native Paper.
@crystalarcus sorry for the late response, but i've already use another module called react-native-switch with some cutomization.
but still thank you for your contributions.
@crystalarcus sorry for the late response, but i've already use another module called
react-native-switchwith some cutomization.
Ya, initially i considered that option too, but I wanted to add that fluid like animation while switching from Material 3, so I made my won component. It is a good alternative too
Whats the update on this? Was this merged into React Native Paper officially?
@Santhosh-Umapathi It can't be directly merged into React Native Paper but I can make a npm package which u can install and directly use
MaterialSwitchcomponent with React Native Paper. Or if you need it urgently you can just copy the Switch Components files from snack
Awesome thanks, I will copy the files from the snack. But a npm package could be really helpful for the community as well. If you have free time to work on the package, that would be greatly appreciated :)
@crystalarcus Have you tried this with expo SDK 52? I tried the code from the snack and its working fine on iOS and android but throws a bunch of errors on web.
@crystalarcus Have you tried this with expo SDK 52? I tried the code from the snack and its working fine on iOS and android but throws a bunch of errors on web.
Haven't used it for long, I will check and see if everything's working fine