-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename HotwireCore -> Hotwire and use extension functions in the navi…
…gation module to extend the Hotwire.* configuration options
- Loading branch information
Showing
22 changed files
with
127 additions
and
113 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
2 changes: 1 addition & 1 deletion
2
...in/dev/hotwire/core/config/HotwireCore.kt → ...kotlin/dev/hotwire/core/config/Hotwire.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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package dev.hotwire.core.config | ||
|
||
object HotwireCore { | ||
object Hotwire { | ||
val config: HotwireConfig = HotwireConfig() | ||
} |
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
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
12 changes: 6 additions & 6 deletions
12
core/src/test/kotlin/dev/hotwire/core/bridge/UserAgentTest.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 |
---|---|---|
@@ -1,24 +1,24 @@ | ||
package dev.hotwire.core.bridge | ||
|
||
import dev.hotwire.core.config.HotwireCore | ||
import dev.hotwire.core.config.Hotwire | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class UserAgentTest { | ||
@Test | ||
fun userAgentSubstring() { | ||
HotwireCore.config.registeredBridgeComponentFactories = TestData.componentFactories | ||
Hotwire.config.registeredBridgeComponentFactories = TestData.componentFactories | ||
|
||
val userAgentSubstring = HotwireCore.config.userAgentSubstring() | ||
val userAgentSubstring = Hotwire.config.userAgentSubstring() | ||
assertEquals(userAgentSubstring, "Turbo Native Android; bridge-components: [one two];") | ||
} | ||
|
||
@Test | ||
fun userAgent() { | ||
HotwireCore.config.registeredBridgeComponentFactories = TestData.componentFactories | ||
HotwireCore.config.userAgent = "Test; ${HotwireCore.config.userAgentSubstring()}" | ||
Hotwire.config.registeredBridgeComponentFactories = TestData.componentFactories | ||
Hotwire.config.userAgent = "Test; ${Hotwire.config.userAgentSubstring()}" | ||
|
||
val userAgent = HotwireCore.config.userAgent | ||
val userAgent = Hotwire.config.userAgent | ||
assertEquals(userAgent, "Test; Turbo Native Android; bridge-components: [one two];") | ||
} | ||
} |
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
67 changes: 0 additions & 67 deletions
67
navigation-fragments/src/main/java/dev/hotwire/navigation/config/Hotwire.kt
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
navigation-fragments/src/main/java/dev/hotwire/navigation/config/HotwireNavigation.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,65 @@ | ||
package dev.hotwire.navigation.config | ||
|
||
import androidx.fragment.app.Fragment | ||
import dev.hotwire.core.bridge.BridgeComponent | ||
import dev.hotwire.core.bridge.BridgeComponentFactory | ||
import dev.hotwire.core.config.Hotwire | ||
import dev.hotwire.navigation.destinations.HotwireNavDestination | ||
import dev.hotwire.navigation.fragments.HotwireWebBottomSheetFragment | ||
import dev.hotwire.navigation.fragments.HotwireWebFragment | ||
import dev.hotwire.navigation.routing.AppNavigationRouteDecisionHandler | ||
import dev.hotwire.navigation.routing.BrowserRouteDecisionHandler | ||
import dev.hotwire.navigation.routing.Router | ||
import kotlin.reflect.KClass | ||
|
||
internal object HotwireNavigation { | ||
var router = Router(listOf( | ||
AppNavigationRouteDecisionHandler(), | ||
BrowserRouteDecisionHandler() | ||
)) | ||
|
||
var defaultFragmentDestination: KClass<out Fragment> = HotwireWebFragment::class | ||
|
||
var registeredFragmentDestinations: List<KClass<out Fragment>> = listOf( | ||
HotwireWebFragment::class, | ||
HotwireWebBottomSheetFragment::class | ||
) | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
var registeredBridgeComponentFactories: List<BridgeComponentFactory<HotwireNavDestination, BridgeComponent<HotwireNavDestination>>> | ||
get() = Hotwire.config.registeredBridgeComponentFactories as List<BridgeComponentFactory<HotwireNavDestination, BridgeComponent<HotwireNavDestination>>> | ||
set(value) { Hotwire.config.registeredBridgeComponentFactories = value } | ||
} | ||
|
||
/** | ||
* Registers the [Router.RouteDecisionHandler] instances that determine whether to route location | ||
* urls within in-app navigation or with alternative custom behaviors. | ||
*/ | ||
fun Hotwire.registerRouteDecisionHandlers(decisionHandlers: List<Router.RouteDecisionHandler>) { | ||
HotwireNavigation.router = Router(decisionHandlers) | ||
} | ||
|
||
/** | ||
* Register bridge components that the app supports. Every possible bridge | ||
* component, wrapped in a [BridgeComponentFactory], must be provided here. | ||
*/ | ||
fun Hotwire.registerBridgeComponents(factories: List<BridgeComponentFactory<HotwireNavDestination, BridgeComponent<HotwireNavDestination>>>) { | ||
config.registeredBridgeComponentFactories = factories | ||
} | ||
|
||
/** | ||
* The default fragment destination for web requests. If you have not | ||
* loaded a path configuration with a matching rule and a `uri` available | ||
* for all possible paths, this destination will be used as the default. | ||
*/ | ||
var Hotwire.defaultFragmentDestination: KClass<out Fragment> | ||
get() = HotwireNavigation.defaultFragmentDestination | ||
set(value) { HotwireNavigation.defaultFragmentDestination = value } | ||
|
||
/** | ||
* Register fragment destinations that can be navigated to. Every possible | ||
* destination must be provided here. | ||
*/ | ||
fun Hotwire.registerFragmentDestinations(destinations: List<KClass<out Fragment>>) { | ||
HotwireNavigation.registeredFragmentDestinations = destinations | ||
} |
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.