|
|
@ -1,11 +1,16 @@ |
|
|
|
package org.jetbrains.compose.demo.widgets.ui |
|
|
|
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.Column |
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.fillMaxSize |
|
|
|
import androidx.compose.foundation.rememberScrollState |
|
|
|
import androidx.compose.foundation.rememberScrollState |
|
|
|
import androidx.compose.foundation.verticalScroll |
|
|
|
import androidx.compose.foundation.verticalScroll |
|
|
|
import androidx.compose.runtime.Composable |
|
|
|
import androidx.compose.runtime.Composable |
|
|
|
import androidx.compose.runtime.MutableState |
|
|
|
import androidx.compose.runtime.MutableState |
|
|
|
import androidx.compose.ui.Modifier |
|
|
|
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.* |
|
|
|
import org.jetbrains.compose.demo.widgets.ui.screens.* |
|
|
|
|
|
|
|
|
|
|
|
@Composable |
|
|
|
@Composable |
|
|
@ -13,6 +18,7 @@ fun WidgetsView( |
|
|
|
widgetsTypeState: MutableState<WidgetsType>, |
|
|
|
widgetsTypeState: MutableState<WidgetsType>, |
|
|
|
modifier: Modifier |
|
|
|
modifier: Modifier |
|
|
|
) { |
|
|
|
) { |
|
|
|
|
|
|
|
ClearFocusBox { |
|
|
|
Column(modifier = modifier.verticalScroll(state = rememberScrollState())) { |
|
|
|
Column(modifier = modifier.verticalScroll(state = rememberScrollState())) { |
|
|
|
@Suppress("UNUSED_VARIABLE") |
|
|
|
@Suppress("UNUSED_VARIABLE") |
|
|
|
val exhaustive = when (widgetsTypeState.value) { |
|
|
|
val exhaustive = when (widgetsTypeState.value) { |
|
|
@ -28,3 +34,22 @@ fun WidgetsView( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 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() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|