From 41fbc992083c76751b85c3f08969b53f183704e0 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Tue, 19 Nov 2024 16:30:12 -0500 Subject: [PATCH] Use the new insets API in EmojiSearch --- .../app/cash/redwood/lazylayout/uiview/UIViewLazyList.kt | 2 ++ .../emojisearch/android/views/EmojiSearchActivity.kt | 4 ++-- .../com/example/redwood/emojisearch/desktop/main.kt | 2 +- .../example/redwood/emojisearch/presenter/EmojiSearch.kt | 8 ++++++-- .../emojisearch/presenter/EmojiSearchTreehouseUi.kt | 9 ++++++++- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/redwood-lazylayout-uiview/src/commonMain/kotlin/app/cash/redwood/lazylayout/uiview/UIViewLazyList.kt b/redwood-lazylayout-uiview/src/commonMain/kotlin/app/cash/redwood/lazylayout/uiview/UIViewLazyList.kt index d9da6ff0c2..25f5468cbe 100644 --- a/redwood-lazylayout-uiview/src/commonMain/kotlin/app/cash/redwood/lazylayout/uiview/UIViewLazyList.kt +++ b/redwood-lazylayout-uiview/src/commonMain/kotlin/app/cash/redwood/lazylayout/uiview/UIViewLazyList.kt @@ -50,6 +50,7 @@ import platform.UIKit.UIControlEventValueChanged import platform.UIKit.UIEdgeInsetsMake import platform.UIKit.UIRefreshControl import platform.UIKit.UIScrollView +import platform.UIKit.UIScrollViewContentInsetAdjustmentBehavior.UIScrollViewContentInsetAdjustmentNever import platform.UIKit.UITableView import platform.UIKit.UITableViewAutomaticDimension import platform.UIKit.UITableViewCell @@ -275,6 +276,7 @@ internal class UIViewLazyList : rowHeight = UITableViewAutomaticDimension separatorStyle = UITableViewCellSeparatorStyleNone backgroundColor = UIColor.clearColor + contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever registerClass( cellClass = LazyListContainerCell(UITableViewCellStyle.UITableViewCellStyleDefault, REUSE_IDENTIFIER) diff --git a/samples/emoji-search/android-views/src/main/kotlin/com/example/redwood/emojisearch/android/views/EmojiSearchActivity.kt b/samples/emoji-search/android-views/src/main/kotlin/com/example/redwood/emojisearch/android/views/EmojiSearchActivity.kt index 0acc5924bb..a52b5b13d9 100644 --- a/samples/emoji-search/android-views/src/main/kotlin/com/example/redwood/emojisearch/android/views/EmojiSearchActivity.kt +++ b/samples/emoji-search/android-views/src/main/kotlin/com/example/redwood/emojisearch/android/views/EmojiSearchActivity.kt @@ -21,7 +21,7 @@ import android.os.Bundle import android.util.Log import android.view.View import androidx.activity.ComponentActivity -import androidx.core.view.WindowCompat +import androidx.activity.enableEdgeToEdge import app.cash.redwood.compose.AndroidUiDispatcher.Companion.Main import app.cash.redwood.layout.view.ViewRedwoodLayoutWidgetFactory import app.cash.redwood.lazylayout.view.ViewRedwoodLazyLayoutWidgetFactory @@ -75,8 +75,8 @@ class EmojiSearchActivity : ComponentActivity() { @SuppressLint("ResourceType") override fun onCreate(savedInstanceState: Bundle?) { + enableEdgeToEdge() super.onCreate(savedInstanceState) - WindowCompat.setDecorFitsSystemWindows(window, false) val context = this val treehouseApp = createTreehouseApp() diff --git a/samples/emoji-search/desktop-composeui/src/main/kotlin/com/example/redwood/emojisearch/desktop/main.kt b/samples/emoji-search/desktop-composeui/src/main/kotlin/com/example/redwood/emojisearch/desktop/main.kt index dc42b8ac06..8fb0e47dc5 100644 --- a/samples/emoji-search/desktop-composeui/src/main/kotlin/com/example/redwood/emojisearch/desktop/main.kt +++ b/samples/emoji-search/desktop-composeui/src/main/kotlin/com/example/redwood/emojisearch/desktop/main.kt @@ -62,7 +62,7 @@ fun main() { EmojiSearch( httpClient = httpClient, navigator = DesktopNavigator, - safeAreaInsets = Margin.Zero, + viewInsets = Margin.Zero, ) } } diff --git a/samples/emoji-search/presenter/src/commonMain/kotlin/com/example/redwood/emojisearch/presenter/EmojiSearch.kt b/samples/emoji-search/presenter/src/commonMain/kotlin/com/example/redwood/emojisearch/presenter/EmojiSearch.kt index f1f2a8cda9..29d05e9397 100644 --- a/samples/emoji-search/presenter/src/commonMain/kotlin/com/example/redwood/emojisearch/presenter/EmojiSearch.kt +++ b/samples/emoji-search/presenter/src/commonMain/kotlin/com/example/redwood/emojisearch/presenter/EmojiSearch.kt @@ -35,6 +35,7 @@ import app.cash.redwood.layout.api.CrossAxisAlignment import app.cash.redwood.layout.api.MainAxisAlignment import app.cash.redwood.layout.compose.Column import app.cash.redwood.layout.compose.Row +import app.cash.redwood.layout.compose.Spacer import app.cash.redwood.lazylayout.compose.ExperimentalRedwoodLazyLayoutApi import app.cash.redwood.lazylayout.compose.LazyColumn import app.cash.redwood.lazylayout.compose.items @@ -71,7 +72,7 @@ fun EmojiSearch( httpClient: HttpClient, navigator: Navigator, modifier: Modifier = Modifier, - safeAreaInsets: Margin = LocalUiConfiguration.current.safeAreaInsets, + viewInsets: Margin = LocalUiConfiguration.current.safeAreaInsets, ) { val scope = rememberCoroutineScope() val allEmojis = remember { mutableStateListOf() } @@ -123,7 +124,7 @@ fun EmojiSearch( width = Constraint.Fill, height = Constraint.Fill, horizontalAlignment = CrossAxisAlignment.Stretch, - margin = safeAreaInsets, + margin = Margin(start = viewInsets.start, end = viewInsets.end, top = viewInsets.top), modifier = modifier, ) { TextInput( @@ -166,6 +167,9 @@ fun EmojiSearch( }, ) } + item { + Spacer(height = viewInsets.bottom) + } } } } diff --git a/samples/emoji-search/presenter/src/jsMain/kotlin/com/example/redwood/emojisearch/presenter/EmojiSearchTreehouseUi.kt b/samples/emoji-search/presenter/src/jsMain/kotlin/com/example/redwood/emojisearch/presenter/EmojiSearchTreehouseUi.kt index 708720f471..e55e92f67a 100644 --- a/samples/emoji-search/presenter/src/jsMain/kotlin/com/example/redwood/emojisearch/presenter/EmojiSearchTreehouseUi.kt +++ b/samples/emoji-search/presenter/src/jsMain/kotlin/com/example/redwood/emojisearch/presenter/EmojiSearchTreehouseUi.kt @@ -16,6 +16,7 @@ package com.example.redwood.emojisearch.presenter import androidx.compose.runtime.Composable +import app.cash.redwood.compose.ConsumeInsets import app.cash.redwood.treehouse.TreehouseUi class EmojiSearchTreehouseUi( @@ -24,6 +25,12 @@ class EmojiSearchTreehouseUi( ) : TreehouseUi { @Composable override fun Show() { - EmojiSearch(httpClient, navigator) + ConsumeInsets { insets -> + EmojiSearch( + httpClient = httpClient, + navigator = navigator, + viewInsets = insets, + ) + } } }