Skip to content

Commit

Permalink
feat: refactor get route methods
Browse files Browse the repository at this point in the history
  • Loading branch information
foxsofter committed Nov 4, 2020
1 parent 4780c51 commit e9b7a39
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ package com.hellobike.flutter.thrio.module

import android.app.Application
import android.content.Context
import com.hellobike.flutter.thrio.navigator.ActivityDelegate
import com.hellobike.flutter.thrio.navigator.FlutterEngineFactory
import com.hellobike.flutter.thrio.navigator.IntentBuilders
import com.hellobike.flutter.thrio.navigator.Log
import com.hellobike.flutter.thrio.navigator.ThrioNavigator

open class ThrioModule {
private val modules by lazy { mutableMapOf<Class<out ThrioModule>, ThrioModule>() }
Expand All @@ -38,18 +37,19 @@ open class ThrioModule {

@JvmStatic
fun init(context: Application, module: ThrioModule) {
context.registerActivityLifecycleCallbacks(ActivityDelegate)

root.registerModule(context, module)
root.initModule(context)
ThrioNavigator.init(context)
}

@JvmStatic
fun init(context: Application, module: ThrioModule, multiEngineEnabled: Boolean) {
FlutterEngineFactory.isMultiEngineEnabled = multiEngineEnabled
context.registerActivityLifecycleCallbacks(ActivityDelegate)

root.registerModule(context, module)
root.initModule(context)
ThrioNavigator.init(context)
}
}

Expand All @@ -68,6 +68,9 @@ open class ThrioModule {
modules.values.forEach {
it.onPageRegister(context)
}
if (!FlutterEngineFactory.isMultiEngineEnabled) {
FlutterEngineFactory.startup(context)
}
}

protected open fun onModuleRegister(context: Context) {}
Expand All @@ -76,9 +79,15 @@ open class ThrioModule {

protected open fun onModuleInit(context: Context) {}

protected open var navigatorLogEnabled
protected var navigatorLogEnabled
get() = Log.navigatorLogging
set(enabled) {
Log.navigatorLogging = enabled
}

protected fun startupFlutterEngine(context: Context, entrypoint: String) {
if (!FlutterEngineFactory.isMultiEngineEnabled) {
FlutterEngineFactory.startup(context, entrypoint)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ internal object PageRoutes : Application.ActivityLifecycleCallbacks {
return holder?.lastRoute()
}

fun allRoute(url: String): List<PageRoute> {
fun allRoutes(url: String): List<PageRoute> {
val allRoutes = mutableListOf<PageRoute>()
for (i in routeHolders.size - 1 downTo 0) {
val holder = routeHolders[i]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal class RouteReceiveChannel(private val channel: ThrioChannel,
onPopTo()
onRemove()
onLastIndex()
onGetAllIndex()
onGetAllIndexs()
onSetPopDisabled()
onHotRestart()
onRegisterUrls()
Expand Down Expand Up @@ -103,8 +103,8 @@ internal class RouteReceiveChannel(private val channel: ThrioChannel,
channel.registryMethod("lastIndex") { _, _ -> }
}

private fun onGetAllIndex() {
channel.registryMethod("getAllIndex") { _, _ -> }
private fun onGetAllIndexs() {
channel.registryMethod("getAllIndexs") { _, _ -> }
}

private fun onSetPopDisabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ object ThrioNavigator {
NAVIGATION_NATIVE_ENTRYPOINT, poppedResult, result)
}


@JvmStatic
@JvmOverloads
fun pop(params: Any? = null,
Expand Down Expand Up @@ -79,12 +78,10 @@ object ThrioNavigator {
NavigationController.Notify.notify(url, index, name, params, result)
}

internal fun init(context: Application) {
if (!FlutterEngineFactory.isMultiEngineEnabled) {
FlutterEngineFactory.startup(context)
}
context.registerActivityLifecycleCallbacks(ActivityDelegate)
}
}

@JvmStatic
@JvmOverloads
fun lastRoute(url: String? = null): PageRoute? = PageRoutes.lastRoute(url)

@JvmStatic
fun allRoutes(url: String): List<PageRoute> = PageRoutes.allRoutes(url);
}
Loading

0 comments on commit e9b7a39

Please sign in to comment.