-
Notifications
You must be signed in to change notification settings - Fork 65
Update web sample with dynamic web scaling #646
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
base: 2.x
Are you sure you want to change the base?
Changes from 6 commits
7a45466
9d05f20
721e6bf
a86edff
686ce6b
f460384
7cd90df
58ca885
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,8 @@ import androidx.compose.ui.input.key.key | |
| import androidx.compose.ui.input.key.onKeyEvent | ||
| import androidx.compose.ui.input.key.type | ||
| import androidx.compose.ui.layout.onSizeChanged | ||
| import androidx.compose.ui.platform.LocalDensity | ||
| import androidx.compose.ui.unit.Density | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.compose.ui.window.CanvasBasedWindow | ||
| import com.bumble.appyx.demos.appyxSample | ||
|
|
@@ -47,6 +49,8 @@ import kotlinx.coroutines.channels.Channel | |
| import kotlinx.coroutines.flow.receiveAsFlow | ||
| import kotlinx.coroutines.launch | ||
|
|
||
| private val containerShape = RoundedCornerShape(8) | ||
|
|
||
| @OptIn(ExperimentalComposeUiApi::class) | ||
| fun main() { | ||
| val events: Channel<Unit> = Channel() | ||
|
|
@@ -58,11 +62,9 @@ fun main() { | |
| } | ||
| } | ||
|
|
||
| private val containerShape = RoundedCornerShape(8) | ||
|
|
||
| @Composable | ||
| private fun CakeApp(events: Channel<Unit>, navigator: Navigator) { | ||
| AppyxSampleAppTheme(darkTheme = true, themeTypography = webTypography) { | ||
| AppyxSampleAppTheme(darkTheme = true) { | ||
| val requester = remember { FocusRequester() } | ||
| var hasFocus by remember { mutableStateOf(false) } | ||
|
|
||
|
|
@@ -81,7 +83,7 @@ private fun CakeApp(events: Channel<Unit>, navigator: Navigator) { | |
| .onFocusChanged { hasFocus = it.hasFocus }, | ||
| color = MaterialTheme.colorScheme.background, | ||
| ) { | ||
| CompositionLocalProvider(LocalNavigator provides navigator) { | ||
| ProvideScopeConfiguration(navigator, screenSize) { | ||
| BlackContainer { | ||
| WebNodeHost( | ||
| screenSize = screenSize, | ||
|
|
@@ -123,6 +125,27 @@ private fun BlackContainer(content: @Composable () -> Unit) { | |
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun ProvideScopeConfiguration( | ||
| navigator: Navigator, | ||
| screenSize: ScreenSize, | ||
| body: @Composable () -> Unit | ||
| ) { | ||
| CompositionLocalProvider( | ||
| LocalDensity provides screenSize.calculateDensityFromScreenSize(), | ||
| LocalNavigator provides navigator, | ||
| ) { | ||
| body() | ||
| } | ||
| } | ||
|
|
||
| private fun ScreenSize.calculateDensityFromScreenSize(): Density = | ||
| if (widthDp.value < 1500) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should it be a proportional value coerced in (0.75f, 4f)? |
||
| Density(1.2f, 1f) | ||
| } else { | ||
| Density(1.8f, 1.2f) | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks weird to me. Why is it specifically |
||
|
|
||
| private fun onKeyEvent( | ||
| keyEvent: KeyEvent, | ||
| events: Channel<Unit>, | ||
|
|
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.