-
-
Save chuross/fdd37eb026cd5689ded6e004ecca688a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| val router = MoriRouter.from(fm, R.id.container) | |
| router.pop() | |
| router.hoge().start() | |
| router.hoge(fuga).start() | |
| router.hoge(fuga).piyo(foo).start() | |
| // SharedElement support | |
| router.hoge().shareFooImage(imageView).start() | |
| router.dispatch(Uri.parse("example://foo/1")) | |
| ----- | |
| @RouterPath( | |
| name = "hoge", | |
| uri = "example://foo/{id}", | |
| transitionNames = *arrayOf("fooImage"), | |
| enterTransitionFactory = ExplodeSetFactory.class, | |
| exitTransitionFactory = ExplodeSetFactory.class | |
| ) | |
| class HogeFragment | |
| @RouterParam | |
| lateinit var fuga: Fuga | |
| @RouterParam(name = "piyo", required = false) | |
| var piyo: String? = null | |
| @RouterPathParam(name = "id") | |
| var fooId: String? = null |
This file contains hidden or 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
| router.dispatch(Uri.parse("morirouter://second/1")) | |
| --- | |
| val dispatcher: UriDispatcher = UriDispatcher(this) // this = MoriRouter | |
| fun dispatch(uri: Uri) = dispatcher.dispatch(uri) | |
| --- | |
| class UriDispatcher | |
| val launchers = listOf( | |
| {RouterPath}UriLauncer(router) | |
| ... | |
| ) | |
| launchers.forEach { | |
| if (!it.isAvailable(uri)) return@forEach | |
| it.launch(uri) | |
| } | |
| --- | |
| class {RouterPath}UriLauncher | |
| private val router: MoriRouter | |
| private val format: String = "morirouter://foo/{id}" //使わなそう | |
| private val uriRegex: Regex = "morirouter://foo/([^\/]+)\/?$" | |
| fun isAvailable(uri: Uri): Boolean = uriRegex.matches(uri.toString()) | |
| fun launch(uri: Uri) { | |
| if (!isAvailable(uri)) throw IllegalArgumentExeption("error!!") | |
| val groupValues = uriRegex.find(uri.toString())?.groupValues ?: throw IllegalStateExeption("generate regex error. please pull request!") | |
| val id = groupValues[1] | |
| router.{RouterPath.name}().id(id).launch() | |
| } | |
| --- | |
| val format: String = "morirouter://foo/{id}" | |
| ↓ | |
| val uriRegex: Regex = format.replace("""\{[0-9a-zA-Z_-]\}""".toRegex(), "(.+)").toRegex() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment