File tree Expand file tree Collapse file tree 2 files changed +26
-5
lines changed
library/src/enabled/java/com/telefonica/tweaks Expand file tree Collapse file tree 2 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -275,10 +275,17 @@ addTweakGraph(
275
275
```
276
276
277
277
## Shake gesture support:
278
- The tweaks can be opened when the user shakes the device, to do this you need to add to your navigation controller:
278
+
279
+ The tweaks can be opened when the user shakes the device. To achieve this, you can either add the following to your navigation controller:
279
280
``` kotlin
280
281
navController.navigateToTweaksOnShake()
281
282
```
283
+ or call:
284
+ ``` kotlin
285
+ NavigateToTweaksOnShake (onOpenTweaks: () -> Unit )
286
+ ```
287
+ and handle the navigation action yourself.
288
+
282
289
And also, optionally
283
290
``` xml
284
291
<uses-permission android : name =" android.permission.VIBRATE" />
Original file line number Diff line number Diff line change @@ -90,12 +90,24 @@ open class Tweaks : TweaksContract {
90
90
component.inject(reference)
91
91
}
92
92
}
93
+ }
93
94
95
+ @Composable
96
+ fun NavController.navigateToTweaksOnShake () {
97
+ DetectShakeAndNavigate {
98
+ navigate(TWEAKS_NAVIGATION_ENTRYPOINT )
99
+ }
100
+ }
94
101
102
+ @Composable
103
+ fun NavigateToTweaksOnShake (onOpenTweaks : () -> Unit ) {
104
+ DetectShakeAndNavigate {
105
+ onOpenTweaks()
106
+ }
95
107
}
96
108
97
109
@Composable
98
- fun NavController. navigateToTweaksOnShake ( ) {
110
+ private fun DetectShakeAndNavigate ( onShakeDetected : () -> Unit ) {
99
111
val context = LocalContext .current
100
112
val sensorManager: SensorManager =
101
113
context.getSystemService(Context .SENSOR_SERVICE ) as SensorManager
@@ -110,13 +122,15 @@ fun NavController.navigateToTweaksOnShake() {
110
122
shakeDetector.start(sensorManager, SensorManager .SENSOR_DELAY_NORMAL )
111
123
}
112
124
113
- if (shouldNavigate) {
114
- LaunchedEffect (shouldNavigate) {
115
- navigate(TWEAKS_NAVIGATION_ENTRYPOINT )
125
+ LaunchedEffect (shouldNavigate) {
126
+ if (shouldNavigate) {
127
+ onShakeDetected()
128
+ shouldNavigate = false
116
129
}
117
130
}
118
131
}
119
132
133
+
120
134
@SuppressLint(" MissingPermission" )
121
135
private fun vibrateIfAble (context : Context ) {
122
136
if (ContextCompat .checkSelfPermission(
You can’t perform that action at this time.
0 commit comments