1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-09 12:32:30 +01:00

Load url on webview initialization

This commit is contained in:
Allan Wang 2023-06-20 02:07:55 -07:00
parent 5544d1882b
commit 38f0312610
No known key found for this signature in database
GPG Key ID: C93E3F9C679D7A56
2 changed files with 8 additions and 19 deletions

View File

@ -64,29 +64,15 @@ class FrostWebCompose(
*
* Based off of
* https://github.com/google/accompanist/blob/main/web/src/main/java/com/google/accompanist/web/WebView.kt
*/
/**
* A wrapper around the Android View WebView to provide a basic WebView composable.
*
* If you require more customisation you are most likely better rolling your own and using this
* wrapper as an example.
*
* The WebView attempts to set the layoutParams based on the Compose modifier passed in. If it is
* incorrectly sizing, use the layoutParams composable function instead.
*
* @param state The webview state holder where the Uri to load is defined.
* @param modifier A compose modifier
* @param captureBackPresses Set to true to have this Composable capture back presses and navigate
* the WebView back.
* @param navigator An optional navigator object that can be used to control the WebView's
* navigation from outside the composable.
* the WebView back. navigation from outside the composable.
* @param onCreated Called when the WebView is first created, this can be used to set additional
* settings on the WebView. WebChromeClient and WebViewClient should not be set here as they
* will be subsequently overwritten after this lambda is called.
* @param onDispose Called when the WebView is destroyed. Provides a bundle which can be saved if
* you need to save and restore state in this WebView.
* @param client Provides access to WebViewClient via subclassing
* @param chromeClient Provides access to WebChromeClient via subclassing
* @param factory An optional WebView factory for using a custom subclass of WebView
*/
@Composable
@ -155,6 +141,9 @@ class FrostWebCompose(
webChromeClient = chromeClient
webViewClient = client
val url = store.state[tabId]?.url
if (url != null) loadUrl(url)
}
.also { webView = it }

View File

@ -16,12 +16,12 @@
*/
package com.pitchedapps.frost.web.state.reducer
import com.pitchedapps.frost.web.state.TabAction
import com.pitchedapps.frost.web.state.TabAction.Action
import com.pitchedapps.frost.web.state.TabAction.ContentAction.UpdateNavigationAction
import com.pitchedapps.frost.web.state.TabAction.ContentAction.UpdateProgressAction
import com.pitchedapps.frost.web.state.TabAction.ContentAction.UpdateTitleAction
import com.pitchedapps.frost.web.state.TabAction.ContentAction.UpdateUrlAction
import com.pitchedapps.frost.web.state.TabAction.ResponseAction
import com.pitchedapps.frost.web.state.TabAction.ResponseAction.LoadUrlResponseAction
import com.pitchedapps.frost.web.state.TabAction.ResponseAction.WebStepResponseAction
import com.pitchedapps.frost.web.state.TabAction.UserAction
@ -42,7 +42,7 @@ internal object ContentStateReducer {
canGoForward = action.canGoForward,
)
is UpdateTitleAction -> state.copy(title = action.title)
is TabAction.UserAction ->
is UserAction ->
state.copy(
transientState =
FrostTransientWebReducer.reduce(
@ -50,7 +50,7 @@ internal object ContentStateReducer {
action,
),
)
is TabAction.ResponseAction ->
is ResponseAction ->
state.copy(
transientState =
FrostTransientFulfillmentWebReducer.reduce(
@ -73,7 +73,7 @@ private object FrostTransientWebReducer {
}
private object FrostTransientFulfillmentWebReducer {
fun reduce(state: TransientWebState, action: TabAction.ResponseAction): TransientWebState {
fun reduce(state: TransientWebState, action: ResponseAction): TransientWebState {
return when (action) {
is LoadUrlResponseAction ->
if (state.targetUrl == action.url) state.copy(targetUrl = null) else state