Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Shake detection convenience extension #33

Open
shubhamsinghmutualmobile opened this issue Apr 7, 2023 · 0 comments
Open

Implement Shake detection convenience extension #33

shubhamsinghmutualmobile opened this issue Apr 7, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@shubhamsinghmutualmobile
Copy link
Collaborator

Implement a convenience composable called rememberShakeDetectionState that will internally use rememberAccelerometerSensorState to get current values from the sensor and based on those values calculate whether the device was shaken or not.

rememberShakeDetectionState will return a @Stable class called ShakeDetectionState that exposes a State<Int> called shakeCount that refers to the number of times a valid shake has been triggered. Also expose a callback named onShakeSuccess or onHit using which a user could trigger an action.

This function also takes parameters like hitCount: Int and @FloatRange(from = 0.0, to 1.0) sensitivity: Float.

Here,

hitCount refers to the number of times the device has to be shaken before shakeCount is considered to be increased (it should default to 2 meaning the user has to shake his device 2 times before the shakeCount increases by 1)

and

sensitivity refers to the force by which the user has to shake the device for it to be considered a hit and the hitCount to increase (it will be a float value between 0f and 1f and the ShakeDetectionState class will expose a companion object that contains some default constant values for sensitivity such as ShakeDetectionState.SENSITIVITY_LOW, ShakeDetectionState.SENSITIVITY_MEDIUM, ShakeDetectionState.SENSITIVITY_HIGH).

Shake Detection Formula ref: https://stackoverflow.com/a/49282110

@shubhamsinghmutualmobile shubhamsinghmutualmobile added the enhancement New feature or request label Apr 7, 2023
@aditya-bhawsar-mm aditya-bhawsar-mm self-assigned this Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants