-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31effba
commit 9d92b4c
Showing
19 changed files
with
353 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...onent-toolkit/src/wasmJsMain/kotlin/com/macaosoftware/component/BrowserComponentRender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.macaosoftware.component | ||
|
||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import com.macaosoftware.component.core.Component | ||
import com.macaosoftware.component.core.deeplink.LocalRootComponentProvider | ||
import com.macaosoftware.plugin.Lifecycle | ||
import com.macaosoftware.plugin.LifecycleEventObserver | ||
|
||
@Composable | ||
fun BrowserComponentRender( | ||
rootComponent: Component | ||
) { | ||
|
||
val lifecycle = remember(rootComponent) { Lifecycle() } | ||
|
||
CompositionLocalProvider( | ||
LocalRootComponentProvider provides rootComponent | ||
) { | ||
rootComponent.Content(Modifier.fillMaxSize()) | ||
/*Box(modifier = Modifier.fillMaxSize()) { | ||
// Should listen for keyboard back instead | ||
FloatingBackButton( | ||
modifier = Modifier.offset(y = 48.dp), | ||
alignment = Alignment.TopStart, | ||
onClick = { webBackPressDispatcher.dispatchBackPressed() } | ||
) | ||
}*/ | ||
} | ||
|
||
LifecycleEventObserver( | ||
lifecycle = lifecycle, | ||
onStart = { | ||
println("Receiving Js.onStart() event") | ||
rootComponent.dispatchActive() | ||
}, | ||
onStop = { | ||
println("Receiving Js.onStop() event") | ||
rootComponent.dispatchInactive() | ||
}, | ||
initializeBlock = { | ||
rootComponent.dispatchAttach() | ||
} | ||
) | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
component-toolkit/src/wasmJsMain/kotlin/com/macaosoftware/plugin/Lifecycle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.macaosoftware.plugin | ||
|
||
class Lifecycle { | ||
|
||
private val platformLifecyclePlugin = DefaultPlatformLifecyclePlugin() | ||
|
||
init { | ||
startObserving() | ||
} | ||
|
||
private fun startObserving() { | ||
started() | ||
} | ||
|
||
fun subscribe(appLifecycleCallback: AppLifecycleCallback) { | ||
platformLifecyclePlugin.subscribe(appLifecycleCallback) | ||
} | ||
|
||
private fun started() { | ||
platformLifecyclePlugin.dispatchAppLifecycleEvent(AppLifecycleEvent.Start) | ||
} | ||
|
||
private fun stopped() { | ||
platformLifecyclePlugin.dispatchAppLifecycleEvent(AppLifecycleEvent.Stop) | ||
} | ||
|
||
fun unsubscribe(appLifecycleCallback: AppLifecycleCallback) { | ||
platformLifecyclePlugin.unsubscribe(appLifecycleCallback) | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
component-toolkit/src/wasmJsMain/kotlin/com/macaosoftware/plugin/LifecycleEventObserver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.macaosoftware.plugin | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.DisposableEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.rememberUpdatedState | ||
|
||
@Composable | ||
fun LifecycleEventObserver( | ||
lifecycle: Lifecycle, | ||
onStart: () -> Unit, | ||
onStop: () -> Unit, | ||
initializeBlock: () -> Unit | ||
) { | ||
// Safely update the current lambdas when a new one is provided | ||
val currentOnStart by rememberUpdatedState(newValue = onStart) | ||
val currentOnStop by rememberUpdatedState(newValue = onStop) | ||
|
||
// If the enclosing lifecycleOwner changes, dispose and reset the effect | ||
DisposableEffect(key1 = initializeBlock, key2 = lifecycle) { | ||
initializeBlock.invoke() | ||
// Create an observer that triggers our remembered callbacks | ||
// when the LifecycleOwner that contains this composable changes its state. | ||
val observer = object : AppLifecycleCallback { | ||
override fun onEvent(appLifecycleEvent: AppLifecycleEvent) { | ||
if (appLifecycleEvent == AppLifecycleEvent.Start) { | ||
currentOnStart() | ||
} else if (appLifecycleEvent == AppLifecycleEvent.Stop) { | ||
currentOnStop() | ||
} | ||
} | ||
} | ||
|
||
// Add the observer to the lifecycle | ||
lifecycle.subscribe(observer) | ||
|
||
// When the effect leaves the Composition, remove the observer | ||
onDispose { | ||
lifecycle.unsubscribe(observer) | ||
println( | ||
"LifecycleEventObserver::Disposing LifecycleEventObserver" | ||
) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
macao-sdk-di-koin/src/wasmJsMain/kotlin/com/macaosoftware/app/MacaoKoinApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.macaosoftware.app | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.SideEffect | ||
import com.macaosoftware.component.BrowserComponentRender | ||
|
||
@Composable | ||
fun MacaoKoinApplication( | ||
applicationState: MacaoKoinApplicationState | ||
) { | ||
|
||
when (val stage = applicationState.stage.value) { | ||
|
||
KoinAppStage.Created -> { | ||
SideEffect { applicationState.start() } | ||
} | ||
|
||
KoinAppStage.Loading -> { | ||
} | ||
|
||
is KoinAppStage.Started -> { | ||
BrowserComponentRender(rootComponent = stage.rootComponent) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.