NativeScript / plugins

@nativescript plugins to help with your developments.
https://docs.nativescript.org/plugins/index.html
Apache License 2.0
189 stars 107 forks source link

fix(haptics): Crash on Android API level under 29 #508

Closed asharghi closed 1 year ago

asharghi commented 1 year ago

Haptics will crash Android devices on version 9 because some of the constants used was not added before sdk version 29. Added a sdk version check

Example of constant: https://developer.android.com/reference/android/os/VibrationEffect#EFFECT_CLICK

CatchABus commented 1 year ago

@asharghi Very nice fix. Since we always try to keep support for older devices, we could perhaps add a workaround for older APIs. Before API 29, we were provided with versions of method vibrate which were eventually deprecated (example: https://developer.android.com/reference/android/os/Vibrator#vibrate(long[],%20int)). In this post, somebody has emulated double and heavy click for older devices: https://stackoverflow.com/a/60233086 With a bit of tweaking we might be able to add click effect too (should be simplier than the two mentioned above).

asharghi commented 1 year ago

Thanks for the feedback. With this PR, I’m not removing support for old devices since it’s not supported in the first place. Just want to prevent a crash with this PR. Hope it will do for now.

NathanWalker commented 1 year ago

Available in 3.0.2 now.