Skip to content

Commit

Permalink
🐜 [iOS]网页下拉菜单添加iOS平台和是否是原生UI的判断,侧滑手势添加是否是iOS平台的判断
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlieatinstinct committed Sep 13, 2024
1 parent 0db5bd0 commit d989e2e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ fun EnvSwitcherRender() {
)
) {
for (switchKey in ENV_SWITCH_KEY.entries) {
val experimental = switchKey.experimental ?: continue
val experimental = switchKey.experimental?.findExperimentalKey() ?: continue
key(switchKey) {
Row(
modifier = Modifier.fillMaxWidth().padding(8.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,15 @@ actual suspend fun deepLinkDoSearch(dwebLinkSearchItem: DwebLinkSearchItem) {
}
}


@Composable
actual fun CommonBrowserView(
viewModel: BrowserViewModel, modifier: Modifier, windowRenderScope: WindowContentRenderScope,
) {
BrowserRender(viewModel, modifier, windowRenderScope)
if (envSwitch.isEnabled(ENV_SWITCH_KEY.BROWSERS_NATIVE_RENDER)) {
NativeBrowserView(viewModel, modifier, windowRenderScope)
}else{
BrowserRender(viewModel, modifier, windowRenderScope)
}
}

@OptIn(ExperimentalForeignApi::class, ExperimentalNativeApi::class, ExperimentalComposeUiApi::class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.dweb_browser.helper.compose

import org.dweb_browser.helper.platform.EnvSwitchCore
import org.dweb_browser.helper.platform.IPureViewController
import org.dweb_browser.helper.platform.isAndroid
import org.dweb_browser.helper.platform.isDesktop
import org.dweb_browser.helper.platform.isIOS
import org.dweb_browser.helper.trueAlso

class EnvSwitch : EnvSwitchCore() {
Expand Down Expand Up @@ -42,14 +46,40 @@ class EnvSwitch : EnvSwitchCore() {
}

val envSwitch = EnvSwitch()
// 1-iOS 2-android 4-desktop 3=> iOS && android
private const val SupportIOS = 1
private const val SupportANDROID = 2
private const val SupportDESKTOP = 4
private const val SupportNATIVE = 8

class ExperimentalKey(
val title: SimpleI18nResource,
val description: SimpleI18nResource,
val brand: String,
val disableVersion: String,
val enableVersion: String,
)
val supportPlatform: Int = SupportIOS or SupportANDROID or SupportDESKTOP
){
fun findExperimentalKey(): ExperimentalKey?{
val isPlatformSupported = when {
IPureViewController.isIOS -> supportPlatform and SupportIOS == SupportIOS
IPureViewController.isAndroid -> supportPlatform and SupportANDROID == SupportANDROID
IPureViewController.isDesktop -> supportPlatform and SupportDESKTOP == SupportDESKTOP
else -> false
}

if(isPlatformSupported){
if(supportPlatform and SupportNATIVE == SupportNATIVE){
if(envSwitch.isEnabled(ENV_SWITCH_KEY.BROWSERS_NATIVE_RENDER)){
return this
}
return null
}
return this
}
return null
}
}

enum class ENV_SWITCH_KEY(
val key: String,
Expand Down Expand Up @@ -114,6 +144,7 @@ enum class ENV_SWITCH_KEY(
enableVersion = "1",
),
),
BROWSERS_NATIVE_RENDER("browser-native-render"),
DWEBVIEW_PULLDOWNWEBMENU(
"dwebview-pullwebmenu",
experimental = ExperimentalKey(
Expand All @@ -127,6 +158,7 @@ enum class ENV_SWITCH_KEY(
brand = "dweb-browser-pullmenu",
disableVersion = "1",
enableVersion = "2",
supportPlatform = SupportIOS or SupportNATIVE
)
),
SCREEN_EDGE_SWIPE_ENABLE(
Expand All @@ -143,6 +175,7 @@ enum class ENV_SWITCH_KEY(
brand = "dweb-edge-swipe",
disableVersion = "1",
enableVersion = "2",
supportPlatform = SupportIOS
)
),
DATA_MANAGER_GUI(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ suspend fun startDwebBrowser(
/// iOS版本默认启用新版桌面
envSwitch.init(ENV_SWITCH_KEY.DESKTOP_STYLE_COMPOSE) { "true" }

/// iOS版本Browser默认不启用原声UI
envSwitch.disable(ENV_SWITCH_KEY.BROWSERS_NATIVE_RENDER)

val launcher = DwebBrowserLauncher(if (debugMode) debugTags else emptyList())
dnsNMM = launcher.dnsNMM
val dnsRuntime = launcher.launch()
Expand Down

0 comments on commit d989e2e

Please sign in to comment.