forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Forward UIViewController status bar APIs to ComposeUIViewControllerDelegate #1378
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7146084
Forward status bar APIs and do a minor cleanup
elijah-semyonov bed918a
Suppress warning
elijah-semyonov 4d7e6b4
Clean up a bit
elijah-semyonov 8aa999b
Add example
elijah-semyonov 7abfc5d
Modify example
elijah-semyonov 0e17e74
Modify example
elijah-semyonov 0229d55
Add documentation
elijah-semyonov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
124 changes: 124 additions & 0 deletions
124
compose/mpp/demo/src/uikitMain/kotlin/androidx/compose/mpp/demo/StatusBarState.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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright 2024 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package androidx.compose.mpp.demo | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.DropdownMenu | ||
import androidx.compose.material.DropdownMenuItem | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.derivedStateOf | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.interop.LocalUIViewController | ||
import androidx.compose.ui.unit.dp | ||
import platform.UIKit.UIStatusBarAnimation | ||
import platform.UIKit.UIStatusBarStyleDarkContent | ||
import platform.UIKit.UIStatusBarStyleDefault | ||
import platform.UIKit.UIStatusBarStyleLightContent | ||
import platform.UIKit.UIView | ||
|
||
private var statusBarStyleIndex by mutableStateOf(0) | ||
val preferredStatusBarStyleValue by derivedStateOf { styleValues[statusBarStyleIndex].second } | ||
|
||
private var statusBarHiddenIndex by mutableStateOf(0) | ||
val prefersStatusBarHiddenValue by derivedStateOf { hiddenValues[statusBarHiddenIndex].second } | ||
|
||
private var statusBarAnimationIndex by mutableStateOf(0) | ||
val preferredStatysBarAnimationValue by derivedStateOf { animationValues[statusBarAnimationIndex].second } | ||
|
||
private val hiddenValues = listOf( | ||
"null" to null, | ||
"True" to true, | ||
"False" to false | ||
) | ||
|
||
private val animationValues = listOf( | ||
"null" to null, | ||
"UIStatusBarAnimationFade" to UIStatusBarAnimation.UIStatusBarAnimationFade, | ||
"UIStatusBarAnimationSlide" to UIStatusBarAnimation.UIStatusBarAnimationSlide | ||
) | ||
|
||
private val styleValues = listOf( | ||
"null" to null, | ||
"UIStatusBarStyleDefault" to UIStatusBarStyleDefault, | ||
"UIStatusBarStyleLightContent" to UIStatusBarStyleLightContent, | ||
"UIStatusBarStyleDarkContent" to UIStatusBarStyleDarkContent | ||
) | ||
|
||
val StatusBarStateExample = Screen.Example("StatusBarState") { | ||
Column(modifier = Modifier.fillMaxSize()) { | ||
Dropdown("preferredStatusBarStyle", styleValues[statusBarStyleIndex].first, styleValues.map { it.first }) { | ||
statusBarStyleIndex = it | ||
} | ||
|
||
Dropdown("prefersStatusBarHidden", hiddenValues[statusBarHiddenIndex].first, hiddenValues.map { it.first }) { | ||
statusBarHiddenIndex = it | ||
} | ||
|
||
Dropdown("preferredStatysBarAnimation", animationValues[statusBarAnimationIndex].first, animationValues.map { it.first }) { | ||
statusBarAnimationIndex = it | ||
} | ||
} | ||
|
||
val viewController = LocalUIViewController.current | ||
LaunchedEffect(statusBarStyleIndex, statusBarHiddenIndex, statusBarAnimationIndex) { | ||
UIView.animateWithDuration(0.3) { | ||
viewController.setNeedsStatusBarAppearanceUpdate() | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun Dropdown( | ||
name: String, | ||
current: String, | ||
all: List<String>, | ||
onSelected: (Int) -> Unit | ||
) { | ||
var expanded by remember { mutableStateOf(false) } | ||
|
||
Box(modifier = Modifier | ||
.padding(16.dp) | ||
.fillMaxWidth() | ||
.clickable { expanded = true }) { | ||
Text("$name: $current") | ||
|
||
DropdownMenu( | ||
expanded = expanded, | ||
onDismissRequest = { expanded = false }) { | ||
all.forEachIndexed { index, item -> | ||
DropdownMenuItem( | ||
onClick = { | ||
onSelected(index) | ||
expanded = false | ||
}) { | ||
Text(item) | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering if we can rework code to get rid of this call when changing status bar appearance settigns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but I guess people know exactly when they want to do it, and it's a trivial piece of code, so better not lock ourselves into some specific behavior.