Skip to content

Commit

Permalink
Use the new insets API in EmojiSearch (#2464)
Browse files Browse the repository at this point in the history
Co-authored-by: Jesse Wilson <[email protected]>
  • Loading branch information
swankjesse and squarejesse authored Nov 21, 2024
1 parent 42676b6 commit 6e172dd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -275,6 +276,7 @@ internal class UIViewLazyList :
rowHeight = UITableViewAutomaticDimension
separatorStyle = UITableViewCellSeparatorStyleNone
backgroundColor = UIColor.clearColor
contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever

registerClass(
cellClass = LazyListContainerCell(UITableViewCellStyle.UITableViewCellStyleDefault, REUSE_IDENTIFIER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fun main() {
EmojiSearch(
httpClient = httpClient,
navigator = DesktopNavigator,
safeAreaInsets = Margin.Zero,
viewInsets = Margin.Zero,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<EmojiImage>() }
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -166,6 +167,9 @@ fun EmojiSearch(
},
)
}
item {
Spacer(height = viewInsets.bottom)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -24,6 +25,12 @@ class EmojiSearchTreehouseUi(
) : TreehouseUi {
@Composable
override fun Show() {
EmojiSearch(httpClient, navigator)
ConsumeInsets { insets ->
EmojiSearch(
httpClient = httpClient,
navigator = navigator,
viewInsets = insets,
)
}
}
}

0 comments on commit 6e172dd

Please sign in to comment.