react-native-paper icon indicating copy to clipboard operation
react-native-paper copied to clipboard

M3 styled switch

Open yuameshi opened this issue 3 years ago • 42 comments

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

Official document

Official document

Diff between M2 & M3

Expected style(M3)

Current style(M2)

yuameshi avatar Apr 02 '23 06:04 yuameshi

@rollingmoai Are you trying it on iOS ? I tried it on Android and Web and Handle isn't having that bug.

crystal7-io avatar Jan 21 '24 04:01 crystal7-io

I have changed it in handle too. Now try it out

crystal7-io avatar Jan 21 '24 04:01 crystal7-io

@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 avatar Jan 21 '24 05:01 rollingmoai

@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 ?

crystal7-io avatar Jan 21 '24 05:01 crystal7-io

@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.

crystal7-io avatar Jan 21 '24 07:01 crystal7-io

@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 ?

Makes sense yeah

rollingmoai avatar Jan 22 '24 02:01 rollingmoai

@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

crystal7-io avatar Jan 22 '24 08:01 crystal7-io

@rollingmoai I will be quite busy for a few days, I will continue to work on Material switch after that.

crystal7-io avatar Jan 24 '24 17:01 crystal7-io

Super glad y'all are working on this!! Thank you so much!

micahlt avatar Feb 09 '24 09:02 micahlt

@rollingmoai The new Switch Component is ready, changes I did :

  1. 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 )
  2. Added descriptionStyle to MaterialSwitchListItem.
  3. 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

crystal7-io avatar Feb 24 '24 11:02 crystal7-io

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 .

crystal7-io avatar Feb 24 '24 11:02 crystal7-io

@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.

crystal7-io avatar Feb 28 '24 04:02 crystal7-io

@lukewalczak any reason this shouldn't be added to React Native Paper officially?

micahlt avatar Feb 28 '24 14:02 micahlt

Hi @crystalarcus ,

Thanks for the amazing work on this.

Whats the update on this? Was this merged into React Native Paper officially?

Santhosh-Umapathi avatar Aug 01 '24 13:08 Santhosh-Umapathi

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

crystal7-io avatar Aug 01 '24 13:08 crystal7-io

@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.

yuameshi avatar Aug 01 '24 13:08 yuameshi

@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

crystal7-io avatar Aug 01 '24 13:08 crystal7-io

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 :)

Santhosh-Umapathi avatar Aug 01 '24 14:08 Santhosh-Umapathi

@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.

sirshad01 avatar Mar 10 '25 04:03 sirshad01

@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

crystal7-io avatar May 27 '25 11:05 crystal7-io