You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
----------------------Edit------------------------------------------------------------
I have commented updated component to match better with Material you in comments bellow this.
This one had some bugs
If in case anyone is looking, I have created a "Material You"-like Swtich Component, behaves smoothly, it's touch behaves like Material you Switch. I have followed Material 3 guidelines for making it.
Here's a video of tapping and draggin actions :
20231217-160756.mp4
If anyone likes it, here's the code for component file:
-------Removing Code as there is updated one at snack here.
Also install libraries which are imported before using
If you don't have reanimated installed, see guide to install reanimated because it needs a couple of extra steps to setup properly.
It works completely fine with( and only with) React Native paper and changes color and theme too according to paperprovider, tested on Android on Web, though on web, if you are on Desktop, it works fine on tap, but if you try to drag it, it dosent change value. If you wanna run only on mobile, I think this would work great.
Also there is attribute for icon : <MaterialSwitch icon={"icon_name"}/>, just pass one of MaterialCommunityIcons name as string and it will render a icon when switch is on.
@lukewalczak I worked a bit off and created a Material you styled switch with reanimated and gesture handler and it can be used with react native paper,
here I am using it in my app :
myapp.mp4
and here is Files by Google app switch :
myfiles.mp4
What do you think, pretty much same ?
I mean the material you styled switch just hits different, it changes whole look of the ui,
Should implement this keeping the current switch, users can use anyone which they want.
@crystalarcus Can you send the updated component file code? Thanks!
@rollingmoai sure!, actually there are 2 components I have made for personal use : MaterialSwitch and MaterialSwitchList
as you see in above video, the switch components is many times used with listitem component,
like you click listitem and it switches the switch. The list item i used above is actualy react-native-paper's List.Item component.
Sadly it's not quite possible to use List item and gesture handler togther, it causes bugs, so in MaterialSwitchList component, you can't control the switch by holding it and moving your fingers, but even the Switch from Files by Google app, as shown in video above can't do that. You can't control it by holding and moving ur finger to change switch, you just simply need to press it, and whole List.Item is pressed. So it behaves like single component.
So I had to make 2 separate components to integrate it with List.Item.
The other component MaterialSwitch, behaves normally like a swtich, you can hold it with fingers, or simply tap it.
I will share the code for both components in few hours, just need some finishing touch to make it useful for others, cause I just designed it for my personal use.
Web (Chrome, Windows , the mouse appears laggy because I was capturing with xbox gamebar) :
MaterialSwitchReactNativeWeb.mp4
here's full code :-
-------Removing Code as there is updated one at snack here.
Alright, now one thing, I am just a high school student, don't know about all components and attributes, I just used the knowledge I had. Just making this much was a tough job for me, so if you can optimize it, it would be great. Also it works well in my apps that I made for practicing, still if you find any bug, you can try fixing it. I know one bug and its, sometimes rarely if you touch on exact border of switch item, the handle circle will get bigger as if you are holding it and it will only get normal if you tap again on switch. It just happens rarely.
I gave you a basic foundation that works pretty well, see if you can make it better, if not you can still directly use it !
Hope it helps someone !
( also can someone tell me how to make a snack of a project I currently have in my pc ? I want to put this on snack, would be better to try it yourself before implementing in your app )
Reacted by rollingmoai, Pokai Chang and Eric Poulin
Material Switch have 5 attributes, ( you can edit code and add more like colors, etc):
selected : boolean // value weather switch will be on or off, true : On, false : Off
onPress : function // function triggered after switch is pressed. ( NOTE: onPress is triggered after the switch changing animation is completed, that is, its passed as a callback to reanimated animation)
switchOnIcon : string or function which returns a icon component // Icon when switch is on, default is null
switchOffIcon : string or function which returns a icon component // Icon when switch is off, default is null
fluid : boolean // fluid like animation when switching, default is false
This one have 11 props, namely : title, description, titleStyle, listStyle, selected, onPress, leftIcon, switchOnIcon, switchOffIcon, rippleColor, fluid
Out of these, five props : selected, onPress, fluid, switchOnIcon, switchOffIcon, are same from material switch mentioned above.
the rest six :
title : "string" for List.Item title (from react-native-paper)
description : "string" for List.Item description (from react-native-paper)
listStyle: style for List.Item (from react-native-paper)
titleStyle: style for Title of List ( you can edit code to change description style, I didnt add it cause it looked fine.)
leftIcon : string or function which returns a icon component // Icon to left side of List.Item, default is null
rippleColor: ripple color of List.Item (from react-native-paper) // default is the one used by List.Item
@rollingmoai would like to add one more thing, the state layer on mouse hover:
I was focused to use it with android, so I didn't gave attention to desktop features. The thing is, the state layer opacity is 0.1 when you click on it, but desktop have mouse, which can be hovered. The opacity on mouse hover is 0.08. Will need to add that for better Desktop experience.
@rollingmoai The new Switch Component is ready, changes I did :
MaterialSwitchListItem only shows fluid animation when clicked on ListItem. 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 on ListItem )
Added descriptionStyle to MaterialSwitchListItem.
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
@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 .
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-switch with 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 MaterialSwitch component 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
Activity
[-]M3 style switch[/-][+]M3 styled switch[/+]yuameshi commentedon Apr 4, 2023
any updates?
lukewalczak commentedon Apr 4, 2023
Hey @yuameshi, nothing has changed from my last comment related to that topic
crystal7-io commentedon Dec 17, 2023
----------------------Edit------------------------------------------------------------
I have commented updated component to match better with Material you in comments bellow this.
This one had some bugs
If in case anyone is looking, I have created a "Material You"-like Swtich Component, behaves smoothly, it's touch behaves like Material you Switch. I have followed Material 3 guidelines for making it.
Here's a video of tapping and draggin actions :
20231217-160756.mp4
If anyone likes it, here's the code for component file:
-------Removing Code as there is updated one at snack here.
Also install libraries which are imported before using
If you don't have reanimated installed, see guide to install reanimated because it needs a couple of extra steps to setup properly.
It works completely fine with( and only with) React Native paper and changes color and theme too according to paperprovider, tested on Android on Web, though on web, if you are on Desktop, it works fine on tap, but if you try to drag it, it dosent change value. If you wanna run only on mobile, I think this would work great.
Also there is attribute for icon : <MaterialSwitch icon={"icon_name"}/>, just pass one of MaterialCommunityIcons name as string and it will render a icon when switch is on.
Hope this heps !
crystal7-io commentedon Jan 18, 2024
@lukewalczak I worked a bit off and created a Material you styled switch with reanimated and gesture handler and it can be used with react native paper,
here I am using it in my app :
myapp.mp4
and here is Files by Google app switch :
myfiles.mp4
What do you think, pretty much same ?
I mean the material you styled switch just hits different, it changes whole look of the ui,
Should implement this keeping the current switch, users can use anyone which they want.
rollingmoai commentedon Jan 19, 2024
@crystalarcus Can you share the updated component file code? Thanks!
crystal7-io commentedon Jan 19, 2024
@rollingmoai sure!, actually there are 2 components I have made for personal use :
MaterialSwitchandMaterialSwitchListas you see in above video, the switch components is many times used with listitem component,
like you click listitem and it switches the switch. The list item i used above is actualy
react-native-paper'sList.Itemcomponent.Sadly it's not quite possible to use List item and gesture handler togther, it causes bugs, so in
MaterialSwitchListcomponent, you can't control the switch by holding it and moving your fingers, but even the Switch from Files by Google app, as shown in video above can't do that. You can't control it by holding and moving ur finger to change switch, you just simply need to press it, and wholeList.Itemis pressed. So it behaves like single component.So I had to make 2 separate components to integrate it with
List.Item.The other component
MaterialSwitch, behaves normally like a swtich, you can hold it with fingers, or simply tap it.I will share the code for both components in few hours, just need some finishing touch to make it useful for others, cause I just designed it for my personal use.
crystal7-io commentedon Jan 19, 2024
@rollingmoai @lukewalczak So here's it finally completed and read to use, here's a video:
Android ( Expo Go ) :
20240119-233030.mp4
Web (Chrome, Windows , the mouse appears laggy because I was capturing with xbox gamebar) :
MaterialSwitchReactNativeWeb.mp4
here's full code :-
-------Removing Code as there is updated one at snack here.
Alright, now one thing, I am just a high school student, don't know about all components and attributes, I just used the knowledge I had. Just making this much was a tough job for me, so if you can optimize it, it would be great. Also it works well in my apps that I made for practicing, still if you find any bug, you can try fixing it. I know one bug and its, sometimes rarely if you touch on exact border of switch item, the handle circle will get bigger as if you are holding it and it will only get normal if you tap again on switch. It just happens rarely.
I gave you a basic foundation that works pretty well, see if you can make it better, if not you can still directly use it !
Hope it helps someone !
( also can someone tell me how to make a snack of a project I currently have in my pc ? I want to put this on snack, would be better to try it yourself before implementing in your app )
crystal7-io commentedon Jan 19, 2024
And here's how to use it :
Material Switch
example:
Material Switch have 5 attributes, ( you can edit code and add more like colors, etc):
Material Switch List Item
example:
This one have 11 props, namely :
title, description, titleStyle, listStyle, selected, onPress, leftIcon, switchOnIcon, switchOffIcon, rippleColor, fluidOut of these, five props : selected, onPress, fluid, switchOnIcon, switchOffIcon, are same from material switch mentioned above.
the rest six :
rollingmoai commentedon Jan 20, 2024
Thanks! Will test this out on iOS when I have time
crystal7-io commentedon Jan 20, 2024
@rollingmoai would like to add one more thing, the state layer on mouse hover:

I was focused to use it with android, so I didn't gave attention to desktop features. The thing is, the state layer opacity is 0.1 when you click on it, but desktop have mouse, which can be hovered. The opacity on mouse hover is 0.08. Will need to add that for better Desktop experience.
rollingmoai commentedon Jan 20, 2024
It might be good to have a prop to set the duration of the animation as well.
P.S., Can you also add type annotations for typescript? If not, I can otherwise add them myself. Thanks!
16 remaining items
crystal7-io commentedon Jan 24, 2024
@rollingmoai I will be quite busy for a few days, I will continue to work on Material switch after that.
micahlt commentedon Feb 9, 2024
Super glad y'all are working on this!! Thank you so much!
crystal7-io commentedon Feb 24, 2024
@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 on
ListItem)descriptionStyletoMaterialSwitchListItem.Also one more thing, I think we shouldn't add
animationTimeScalingprop. 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
crystal7-io commentedon Feb 24, 2024
@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
Themedialog of settings screen. And a there's group of Switches inNote TypeSettings .crystal7-io commentedon Feb 28, 2024
@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.
micahlt commentedon Feb 28, 2024
@lukewalczak any reason this shouldn't be added to React Native Paper officially?
Santhosh-Umapathi commentedon Aug 1, 2024
Hi @crystalarcus ,
Thanks for the amazing work on this.
Whats the update on this? Was this merged into React Native Paper officially?
crystal7-io commentedon Aug 1, 2024
@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 snackyuameshi commentedon Aug 1, 2024
@crystalarcus sorry for the late response, but i've already use another module called
react-native-switchwith some cutomization.but still thank you for your contributions.
crystal7-io commentedon Aug 1, 2024
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
Santhosh-Umapathi commentedon Aug 1, 2024
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 :)
sirshad01 commentedon Mar 10, 2025
@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.
crystal7-io commentedon May 27, 2025
Haven't used it for long, I will check and see if everything's working fine
lgc2333 commentedon Jun 22, 2025
Made a version that switch state strictly follows value prop
(only tested on Android)
Details
rollingmoai commentedon May 29, 2026