forked from DroidKaigi/conference-app-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DroidKaigi#907 from Corvus400/feature/open_setting…
…s_app_from_timetable_detail_snack_bar_compose_multiplatform ✨ [Compose Multiplatform] When you tap the action label on the snack bar that appears when you don't have permission to access the calendar, the iOS Settings app will now open.
- Loading branch information
Showing
4 changed files
with
52 additions
and
10 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
app-ios-shared/src/commonMain/composeResources/values-ja/strings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="permission_required">セッションを予定として追加するには、カレンダーへのアクセス権限が必要です。</string> | ||
<string name="open_settings">設定を開く</string> | ||
</resources> |
1 change: 1 addition & 0 deletions
1
app-ios-shared/src/commonMain/composeResources/values/strings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="permission_required">To add a session as a scheduled event, you need access permission to the calendar.</string> | ||
<string name="open_settings">Open settings.</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 25 additions & 8 deletions
33
...rc/commonMain/kotlin/io/github/droidkaigi/confsched/shared/IosComposeKaigiAppPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,51 @@ | ||
package io.github.droidkaigi.confsched.shared | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import io.github.droidkaigi.confsched.compose.EventEffect | ||
import io.github.droidkaigi.confsched.compose.EventFlow | ||
import io.github.droidkaigi.confsched.droidkaigiui.UserMessageResult.ActionPerformed | ||
import io.github.droidkaigi.confsched.droidkaigiui.providePresenterDefaults | ||
import io.github.droidkaigi.confsched.shared.IosComposeKaigiAppEvent.SettingsAppNavigated | ||
import io.github.droidkaigi.confsched.shared.IosComposeKaigiAppEvent.ShowRequiresAuthorization | ||
|
||
sealed interface IosComposeKaigiAppEvent { | ||
val snackbarMessage: String | ||
|
||
data class ShowRequiresAuthorization( | ||
override val snackbarMessage: String, | ||
val snackbarMessage: String, | ||
val actionLabel: String, | ||
) : IosComposeKaigiAppEvent | ||
|
||
data object SettingsAppNavigated : IosComposeKaigiAppEvent | ||
} | ||
|
||
@Composable | ||
fun iosComposeKaigiAppPresenter( | ||
events: EventFlow<IosComposeKaigiAppEvent> | ||
) : IosComposeKaigiAppUiState = providePresenterDefaults { userMessageStateHolder -> | ||
var shouldGoToSettingsApp by remember { mutableStateOf(false) } | ||
|
||
EventEffect(events) { event -> | ||
when (event) { | ||
is ShowRequiresAuthorization -> { | ||
userMessageStateHolder.showMessage( | ||
val result = userMessageStateHolder.showMessage( | ||
message = event.snackbarMessage, | ||
// TODO Add code to transition to the settings screen when the action button is pressed. | ||
// TODO Perhaps UIApplication.openSettingsURLString can be used to achieve this. | ||
actionLabel = null, | ||
actionLabel = event.actionLabel, | ||
) | ||
if (result == ActionPerformed) { | ||
shouldGoToSettingsApp = true | ||
} | ||
} | ||
|
||
SettingsAppNavigated -> { | ||
shouldGoToSettingsApp = false | ||
} | ||
} | ||
} | ||
IosComposeKaigiAppUiState(userMessageStateHolder) | ||
IosComposeKaigiAppUiState( | ||
userMessageStateHolder = userMessageStateHolder, | ||
shouldGoToSettingsApp = shouldGoToSettingsApp, | ||
) | ||
} |