Browse Source

simplify and adapt iOS examples to Compose 1.5.0 (#3547)

pull/3564/head
dima.avdeev 1 year ago committed by GitHub
parent
commit
dae7d42f73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      examples/chat/iosApp/iosApp/ComposeInsideSwiftUIScreen.swift
  2. 1
      examples/chat/shared/src/commonMain/kotlin/Data.kt
  3. 25
      examples/widgets-gallery/shared/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/WidgetView.kt

3
examples/chat/iosApp/iosApp/ComposeInsideSwiftUIScreen.swift

@ -38,9 +38,8 @@ struct TextInputLayer: View {
textFieldFocused = false
textState = ""
}) {
HStack {
Image(systemName: "arrow.up.circle.fill")
}.tint(Color(red: 0.671, green: 0.365, blue: 0.792))
.tint(Color(red: 0.671, green: 0.365, blue: 0.792))
}
}
}.padding(15).background(RoundedRectangle(cornerRadius: 200).fill(.white).opacity(0.95)).padding(15)

1
examples/chat/shared/src/commonMain/kotlin/Data.kt

@ -37,7 +37,6 @@ object ColorProvider {
if(colors.size == 0) {
colors.addAll(allColors)
}
println(colors.lastIndex)
val idx = Random.nextInt(colors.indices)
val color = colors[idx]
colors.removeAt(idx)

25
examples/widgets-gallery/shared/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/WidgetView.kt

@ -1,11 +1,16 @@
package org.jetbrains.compose.demo.widgets.ui
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalFocusManager
import org.jetbrains.compose.demo.widgets.ui.screens.*
@Composable
@ -13,6 +18,7 @@ fun WidgetsView(
widgetsTypeState: MutableState<WidgetsType>,
modifier: Modifier
) {
ClearFocusBox {
Column(modifier = modifier.verticalScroll(state = rememberScrollState())) {
@Suppress("UNUSED_VARIABLE")
val exhaustive = when (widgetsTypeState.value) {
@ -27,4 +33,23 @@ fun WidgetsView(
WidgetsType.UI_CARDS -> UICards()
}
}
}
}
/**
* This wrapper need to control focus behavior on iOS to hide the keyboard.
*/
@Composable
private fun ClearFocusBox(content: @Composable () -> Unit) {
val focusManager = LocalFocusManager.current
Box(
Modifier.fillMaxSize()
.pointerInput(Unit) {
detectTapGestures {
focusManager.clearFocus(force = true)
}
},
) {
content()
}
}

Loading…
Cancel
Save