mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-11-09 12:32:30 +01:00
Create paging based multi webview layout
This commit is contained in:
parent
4a4fe97d08
commit
c80e30303a
@ -28,7 +28,6 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalLifecycleOwner
|
import androidx.compose.ui.platform.LocalLifecycleOwner
|
||||||
import androidx.compose.ui.viewinterop.AndroidView
|
import androidx.compose.ui.viewinterop.AndroidView
|
||||||
import androidx.core.view.children
|
|
||||||
import androidx.core.widget.NestedScrollView
|
import androidx.core.widget.NestedScrollView
|
||||||
import com.google.common.flogger.FluentLogger
|
import com.google.common.flogger.FluentLogger
|
||||||
import com.pitchedapps.frost.ext.WebTargetId
|
import com.pitchedapps.frost.ext.WebTargetId
|
||||||
@ -85,6 +84,8 @@ class FrostWebCompose(
|
|||||||
|
|
||||||
var webView by remember { mutableStateOf<WebView?>(null) }
|
var webView by remember { mutableStateOf<WebView?>(null) }
|
||||||
|
|
||||||
|
logger.atInfo().log("Webview %s %s", tabId, webView?.hashCode())
|
||||||
|
|
||||||
webView?.let { wv ->
|
webView?.let { wv ->
|
||||||
val lifecycleOwner = LocalLifecycleOwner.current
|
val lifecycleOwner = LocalLifecycleOwner.current
|
||||||
|
|
||||||
@ -164,7 +165,7 @@ class FrostWebCompose(
|
|||||||
},
|
},
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
onRelease = { parentFrame ->
|
onRelease = { parentFrame ->
|
||||||
val wv = parentFrame.children.first() as WebView
|
val wv = parentFrame.getChildAt(0) as WebView
|
||||||
onDispose(wv)
|
onDispose(wv)
|
||||||
logger.atInfo().log("Released webview for %s", tabId)
|
logger.atInfo().log("Released webview for %s", tabId)
|
||||||
},
|
},
|
||||||
|
@ -16,8 +16,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.pitchedapps.frost.main
|
package com.pitchedapps.frost.main
|
||||||
|
|
||||||
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.pager.HorizontalPager
|
||||||
|
import androidx.compose.foundation.pager.rememberPagerState
|
||||||
import androidx.compose.material.ExperimentalMaterialApi
|
import androidx.compose.material.ExperimentalMaterialApi
|
||||||
import androidx.compose.material.pullrefresh.PullRefreshIndicator
|
import androidx.compose.material.pullrefresh.PullRefreshIndicator
|
||||||
import androidx.compose.material.pullrefresh.pullRefresh
|
import androidx.compose.material.pullrefresh.pullRefresh
|
||||||
@ -30,6 +33,7 @@ import androidx.compose.material3.Scaffold
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@ -38,6 +42,7 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import com.pitchedapps.frost.compose.webview.FrostWebCompose
|
||||||
import com.pitchedapps.frost.ext.WebTargetId
|
import com.pitchedapps.frost.ext.WebTargetId
|
||||||
import com.pitchedapps.frost.web.state.FrostWebStore
|
import com.pitchedapps.frost.web.state.FrostWebStore
|
||||||
import com.pitchedapps.frost.web.state.TabListAction.SelectHomeTab
|
import com.pitchedapps.frost.web.state.TabListAction.SelectHomeTab
|
||||||
@ -111,7 +116,34 @@ private fun MainScreenWebContainer(
|
|||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
store = store,
|
store = store,
|
||||||
) {
|
) {
|
||||||
homeTabComposables.find { it.tabId == selectedTab }?.WebView()
|
MainPager(selectedTab, items = homeTabComposables)
|
||||||
|
// homeTabComposables.find { it.tabId == selectedTab }?.WebView()
|
||||||
|
|
||||||
|
// MultiViewContainer(store = store)
|
||||||
|
|
||||||
|
// SampleContainer(selectedTab = selectedTab, items = items)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
|
@Composable
|
||||||
|
fun MainPager(selectedTab: WebTargetId?, items: List<FrostWebCompose>) {
|
||||||
|
|
||||||
|
val pagerState = rememberPagerState { items.size }
|
||||||
|
|
||||||
|
LaunchedEffect(selectedTab, items) {
|
||||||
|
val i = items.indexOfFirst { it.tabId == selectedTab }
|
||||||
|
if (i != -1) {
|
||||||
|
pagerState.scrollToPage(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HorizontalPager(
|
||||||
|
state = pagerState,
|
||||||
|
userScrollEnabled = false,
|
||||||
|
beyondBoundsPageCount = 10, // Do not allow view release
|
||||||
|
) { page ->
|
||||||
|
items[page].WebView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user