@@ -59,7 +59,6 @@ import androidx.compose.runtime.LaunchedEffect
59
59
import androidx.compose.runtime.getValue
60
60
import androidx.compose.runtime.mutableStateOf
61
61
import androidx.compose.runtime.remember
62
- import androidx.compose.runtime.saveable.rememberSaveable
63
62
import androidx.compose.runtime.setValue
64
63
import androidx.compose.ui.Alignment
65
64
import androidx.compose.ui.Modifier
@@ -96,9 +95,6 @@ fun Question(
96
95
} else {
97
96
val permissionsContentModifier = modifier.padding(horizontal = 20 .dp)
98
97
99
- // When true, the permissions request must be presented to the user.
100
- var launchPermissionsRequest by rememberSaveable { mutableStateOf(false ) }
101
-
102
98
val multiplePermissionsState =
103
99
rememberMultiplePermissionsState(question.permissionsRequired)
104
100
@@ -107,28 +103,27 @@ fun Question(
107
103
multiplePermissionsState.allPermissionsGranted -> {
108
104
QuestionContent (question, answer, onAnswer, onAction, modifier)
109
105
}
110
- // The user denied some permissions but a rationale should be shown
111
- multiplePermissionsState.shouldShowRationale -> {
112
- if (! shouldAskPermissions) {
113
- PermissionsDenied (
114
- question.questionText,
115
- openSettings,
116
- permissionsContentModifier
117
- )
118
- } else {
119
- PermissionsRationale (
120
- question,
121
- multiplePermissionsState,
122
- onDoNotAskForPermissions,
123
- permissionsContentModifier
124
- )
106
+ // If user denied some permissions but a rationale should be shown or the user
107
+ // is going to be presented with the permission for the first time. Let's explain
108
+ // why we need the permission
109
+ multiplePermissionsState.shouldShowRationale ||
110
+ ! multiplePermissionsState.permissionRequested ->
111
+ {
112
+ if (! shouldAskPermissions) {
113
+ PermissionsDenied (
114
+ question.questionText,
115
+ openSettings,
116
+ permissionsContentModifier
117
+ )
118
+ } else {
119
+ PermissionsRationale (
120
+ question,
121
+ multiplePermissionsState,
122
+ onDoNotAskForPermissions,
123
+ permissionsContentModifier
124
+ )
125
+ }
125
126
}
126
- }
127
- // The permissions are not granted, the rationale shouldn't be shown to the user,
128
- // and the permissions haven't been requested previously. Request permission!
129
- ! multiplePermissionsState.permissionRequested -> {
130
- launchPermissionsRequest = true
131
- }
132
127
// If the criteria above hasn't been met, the user denied some permission.
133
128
else -> {
134
129
PermissionsDenied (question.questionText, openSettings, permissionsContentModifier)
@@ -139,14 +134,6 @@ fun Question(
139
134
}
140
135
}
141
136
142
- // Trigger a side-effect to request the permissions if they need to be presented to the user
143
- if (launchPermissionsRequest) {
144
- LaunchedEffect (multiplePermissionsState) {
145
- multiplePermissionsState.launchMultiplePermissionRequest()
146
- launchPermissionsRequest = false
147
- }
148
- }
149
-
150
137
// If permissions are denied, inform the caller that can move to the next question
151
138
if (! shouldAskPermissions) {
152
139
LaunchedEffect (true ) {
0 commit comments