diff --git a/core/src/main/assets/json/test-configuration.json b/core/src/main/assets/json/test-configuration.json index ea95136..ff38e98 100644 --- a/core/src/main/assets/json/test-configuration.json +++ b/core/src/main/assets/json/test-configuration.json @@ -9,7 +9,7 @@ ], "properties": { "context": "default", - "uri": "turbo://fragment/web", + "uri": "hotwire://fragment/web", "pull_to_refresh_enabled": true } }, @@ -19,7 +19,7 @@ "/home" ], "properties": { - "uri": "turbo://fragment/web/home", + "uri": "hotwire://fragment/web/home", "presentation": "clear_all" } }, @@ -28,7 +28,7 @@ "/new-home" ], "properties": { - "uri": "turbo://fragment/web/home", + "uri": "hotwire://fragment/web/home", "presentation": "replace_root" } }, @@ -47,7 +47,7 @@ ], "properties": { "context": "modal", - "uri": "turbo://fragment/web/modal", + "uri": "hotwire://fragment/web/modal", "query_string_presentation": "default", "pull_to_refresh_enabled": false } @@ -57,7 +57,7 @@ ".+\\.(?:bmp|gif|heic|jpg|jpeg|png|svg|webp)" ], "properties": { - "uri": "turbo://fragment/image_viewer", + "uri": "hotwire://fragment/image_viewer", "title": "Image Viewer" } }, @@ -91,7 +91,7 @@ ], "properties": { "context": "modal", - "uri": "turbo://fragment/web/modal", + "uri": "hotwire://fragment/web/modal", "presentation": "replace_root" } } diff --git a/demo/src/main/assets/json/configuration.json b/demo/src/main/assets/json/configuration.json index 4868f84..b1bb752 100644 --- a/demo/src/main/assets/json/configuration.json +++ b/demo/src/main/assets/json/configuration.json @@ -7,8 +7,8 @@ ], "properties": { "context": "default", - "uri": "turbo://fragment/web", - "fallback_uri": "turbo://fragment/web", + "uri": "hotwire://fragment/web", + "fallback_uri": "hotwire://fragment/web", "pull_to_refresh_enabled": true } }, @@ -18,7 +18,7 @@ "^/$" ], "properties": { - "uri": "turbo://fragment/web/home", + "uri": "hotwire://fragment/web/home", "presentation": "replace_root" } }, @@ -29,7 +29,7 @@ ], "properties": { "context": "modal", - "uri": "turbo://fragment/web/modal", + "uri": "hotwire://fragment/web/modal", "pull_to_refresh_enabled": false } }, @@ -39,7 +39,7 @@ ], "properties": { "context": "modal", - "uri": "turbo://fragment/web/modal/sheet", + "uri": "hotwire://fragment/web/modal/sheet", "pull_to_refresh_enabled": false } }, @@ -48,7 +48,7 @@ "/numbers$" ], "properties": { - "uri": "turbo://fragment/numbers", + "uri": "hotwire://fragment/numbers", "title": "Numbers" } }, @@ -58,7 +58,7 @@ ], "properties": { "context": "modal", - "uri": "turbo://fragment/numbers/sheet", + "uri": "hotwire://fragment/numbers/sheet", "title": "Number", "description": "This is a native bottom sheet fragment" } @@ -68,7 +68,7 @@ ".+\\.(?:bmp|gif|heic|jpg|jpeg|png|svg|webp)" ], "properties": { - "uri": "turbo://fragment/image_viewer" + "uri": "hotwire://fragment/image_viewer" } } ] diff --git a/demo/src/main/kotlin/dev/hotwire/demo/bridge/FormComponent.kt b/demo/src/main/kotlin/dev/hotwire/demo/bridge/FormComponent.kt index 162f642..260c01a 100644 --- a/demo/src/main/kotlin/dev/hotwire/demo/bridge/FormComponent.kt +++ b/demo/src/main/kotlin/dev/hotwire/demo/bridge/FormComponent.kt @@ -11,7 +11,7 @@ import dev.hotwire.core.bridge.BridgeDelegate import dev.hotwire.core.bridge.Message import dev.hotwire.demo.R import dev.hotwire.demo.databinding.FormComponentSubmitBinding -import dev.hotwire.navigation.destinations.HotwireNavDestination +import dev.hotwire.navigation.destinations.HotwireDestination import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -21,8 +21,8 @@ import kotlinx.serialization.Serializable */ class FormComponent( name: String, - private val delegate: BridgeDelegate -) : BridgeComponent(name, delegate) { + private val delegate: BridgeDelegate +) : BridgeComponent(name, delegate) { private val submitButtonItemId = 37 private var submitMenuItem: MenuItem? = null diff --git a/demo/src/main/kotlin/dev/hotwire/demo/bridge/MenuComponent.kt b/demo/src/main/kotlin/dev/hotwire/demo/bridge/MenuComponent.kt index e572d7b..b5c60ea 100644 --- a/demo/src/main/kotlin/dev/hotwire/demo/bridge/MenuComponent.kt +++ b/demo/src/main/kotlin/dev/hotwire/demo/bridge/MenuComponent.kt @@ -9,7 +9,7 @@ import dev.hotwire.core.bridge.BridgeComponent import dev.hotwire.core.bridge.BridgeDelegate import dev.hotwire.core.bridge.Message import dev.hotwire.demo.databinding.MenuComponentBottomSheetBinding -import dev.hotwire.navigation.destinations.HotwireNavDestination +import dev.hotwire.navigation.destinations.HotwireDestination import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -19,8 +19,8 @@ import kotlinx.serialization.Serializable */ class MenuComponent( name: String, - private val delegate: BridgeDelegate -) : BridgeComponent(name, delegate) { + private val delegate: BridgeDelegate +) : BridgeComponent(name, delegate) { private val fragment: Fragment get() = delegate.destination.fragment diff --git a/demo/src/main/kotlin/dev/hotwire/demo/bridge/OverflowMenuComponent.kt b/demo/src/main/kotlin/dev/hotwire/demo/bridge/OverflowMenuComponent.kt index 569ae83..018e42f 100644 --- a/demo/src/main/kotlin/dev/hotwire/demo/bridge/OverflowMenuComponent.kt +++ b/demo/src/main/kotlin/dev/hotwire/demo/bridge/OverflowMenuComponent.kt @@ -7,7 +7,7 @@ import dev.hotwire.core.bridge.BridgeComponent import dev.hotwire.core.bridge.BridgeDelegate import dev.hotwire.core.bridge.Message import dev.hotwire.demo.R -import dev.hotwire.navigation.destinations.HotwireNavDestination +import dev.hotwire.navigation.destinations.HotwireDestination import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -17,8 +17,8 @@ import kotlinx.serialization.Serializable */ class OverflowMenuComponent( name: String, - private val delegate: BridgeDelegate -) : BridgeComponent(name, delegate) { + private val delegate: BridgeDelegate +) : BridgeComponent(name, delegate) { private val fragment: Fragment get() = delegate.destination.fragment diff --git a/demo/src/main/kotlin/dev/hotwire/demo/features/imageviewer/ImageViewerFragment.kt b/demo/src/main/kotlin/dev/hotwire/demo/features/imageviewer/ImageViewerFragment.kt index 9703e3c..302096a 100644 --- a/demo/src/main/kotlin/dev/hotwire/demo/features/imageviewer/ImageViewerFragment.kt +++ b/demo/src/main/kotlin/dev/hotwire/demo/features/imageviewer/ImageViewerFragment.kt @@ -7,11 +7,11 @@ import android.view.ViewGroup import android.widget.ImageView import coil.load import dev.hotwire.demo.R -import dev.hotwire.navigation.destinations.HotwireDestination +import dev.hotwire.navigation.destinations.HotwireDestinationDeepLink import dev.hotwire.navigation.fragments.HotwireFragment import dev.hotwire.navigation.util.displayBackButtonAsCloseIcon -@HotwireDestination(uri = "turbo://fragment/image_viewer") +@HotwireDestinationDeepLink(uri = "hotwire://fragment/image_viewer") class ImageViewerFragment : HotwireFragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.fragment_image_viewer, container, false) diff --git a/demo/src/main/kotlin/dev/hotwire/demo/features/numbers/NumberBottomSheetFragment.kt b/demo/src/main/kotlin/dev/hotwire/demo/features/numbers/NumberBottomSheetFragment.kt index e3d06c6..a658b01 100644 --- a/demo/src/main/kotlin/dev/hotwire/demo/features/numbers/NumberBottomSheetFragment.kt +++ b/demo/src/main/kotlin/dev/hotwire/demo/features/numbers/NumberBottomSheetFragment.kt @@ -8,10 +8,10 @@ import android.view.ViewGroup import com.google.android.material.textview.MaterialTextView import dev.hotwire.core.turbo.config.PathConfigurationProperties import dev.hotwire.demo.R -import dev.hotwire.navigation.destinations.HotwireDestination +import dev.hotwire.navigation.destinations.HotwireDestinationDeepLink import dev.hotwire.navigation.fragments.HotwireBottomSheetFragment -@HotwireDestination(uri = "turbo://fragment/numbers/sheet") +@HotwireDestinationDeepLink(uri = "hotwire://fragment/numbers/sheet") class NumberBottomSheetFragment : HotwireBottomSheetFragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.fragment_number_bottom_sheet, container, false) diff --git a/demo/src/main/kotlin/dev/hotwire/demo/features/numbers/NumbersFragment.kt b/demo/src/main/kotlin/dev/hotwire/demo/features/numbers/NumbersFragment.kt index d6892c3..5a18321 100644 --- a/demo/src/main/kotlin/dev/hotwire/demo/features/numbers/NumbersFragment.kt +++ b/demo/src/main/kotlin/dev/hotwire/demo/features/numbers/NumbersFragment.kt @@ -8,10 +8,10 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import dev.hotwire.demo.R import dev.hotwire.demo.Urls -import dev.hotwire.navigation.destinations.HotwireDestination +import dev.hotwire.navigation.destinations.HotwireDestinationDeepLink import dev.hotwire.navigation.fragments.HotwireFragment -@HotwireDestination(uri = "turbo://fragment/numbers") +@HotwireDestinationDeepLink(uri = "hotwire://fragment/numbers") class NumbersFragment : HotwireFragment(), NumbersFragmentCallback { private val numbersAdapter = NumbersAdapter(this) diff --git a/demo/src/main/kotlin/dev/hotwire/demo/features/web/WebBottomSheetFragment.kt b/demo/src/main/kotlin/dev/hotwire/demo/features/web/WebBottomSheetFragment.kt index c0bdda8..7b7fc73 100644 --- a/demo/src/main/kotlin/dev/hotwire/demo/features/web/WebBottomSheetFragment.kt +++ b/demo/src/main/kotlin/dev/hotwire/demo/features/web/WebBottomSheetFragment.kt @@ -4,10 +4,10 @@ import android.os.Bundle import android.view.MenuItem import android.view.View import dev.hotwire.demo.R -import dev.hotwire.navigation.destinations.HotwireDestination +import dev.hotwire.navigation.destinations.HotwireDestinationDeepLink import dev.hotwire.navigation.fragments.HotwireWebBottomSheetFragment -@HotwireDestination(uri = "turbo://fragment/web/modal/sheet") +@HotwireDestinationDeepLink(uri = "hotwire://fragment/web/modal/sheet") class WebBottomSheetFragment : HotwireWebBottomSheetFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/demo/src/main/kotlin/dev/hotwire/demo/features/web/WebFragment.kt b/demo/src/main/kotlin/dev/hotwire/demo/features/web/WebFragment.kt index aa11d10..c272df5 100644 --- a/demo/src/main/kotlin/dev/hotwire/demo/features/web/WebFragment.kt +++ b/demo/src/main/kotlin/dev/hotwire/demo/features/web/WebFragment.kt @@ -9,10 +9,10 @@ import dev.hotwire.core.turbo.visit.VisitAction.REPLACE import dev.hotwire.core.turbo.visit.VisitOptions import dev.hotwire.demo.R import dev.hotwire.demo.Urls -import dev.hotwire.navigation.destinations.HotwireDestination +import dev.hotwire.navigation.destinations.HotwireDestinationDeepLink import dev.hotwire.navigation.fragments.HotwireWebFragment -@HotwireDestination(uri = "turbo://fragment/web") +@HotwireDestinationDeepLink(uri = "hotwire://fragment/web") open class WebFragment : HotwireWebFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/demo/src/main/kotlin/dev/hotwire/demo/features/web/WebHomeFragment.kt b/demo/src/main/kotlin/dev/hotwire/demo/features/web/WebHomeFragment.kt index be3919d..21232ce 100644 --- a/demo/src/main/kotlin/dev/hotwire/demo/features/web/WebHomeFragment.kt +++ b/demo/src/main/kotlin/dev/hotwire/demo/features/web/WebHomeFragment.kt @@ -6,10 +6,10 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import dev.hotwire.core.turbo.errors.VisitError -import dev.hotwire.navigation.destinations.HotwireDestination +import dev.hotwire.navigation.destinations.HotwireDestinationDeepLink import dev.hotwire.demo.R -@HotwireDestination(uri = "turbo://fragment/web/home") +@HotwireDestinationDeepLink(uri = "hotwire://fragment/web/home") class WebHomeFragment : WebFragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.fragment_web_home, container, false) diff --git a/demo/src/main/kotlin/dev/hotwire/demo/features/web/WebModalFragment.kt b/demo/src/main/kotlin/dev/hotwire/demo/features/web/WebModalFragment.kt index 85d98b3..9045805 100644 --- a/demo/src/main/kotlin/dev/hotwire/demo/features/web/WebModalFragment.kt +++ b/demo/src/main/kotlin/dev/hotwire/demo/features/web/WebModalFragment.kt @@ -1,6 +1,6 @@ package dev.hotwire.demo.features.web -import dev.hotwire.navigation.destinations.HotwireDestination +import dev.hotwire.navigation.destinations.HotwireDestinationDeepLink -@HotwireDestination(uri = "turbo://fragment/web/modal") +@HotwireDestinationDeepLink(uri = "hotwire://fragment/web/modal") class WebModalFragment : WebFragment() diff --git a/docs/ADVANCED-OPTIONS.md b/docs/ADVANCED-OPTIONS.md index 14c572b..1df64a8 100644 --- a/docs/ADVANCED-OPTIONS.md +++ b/docs/ADVANCED-OPTIONS.md @@ -14,7 +14,7 @@ In its simplest form, your web Fragment will look like: **`WebFragment.kt`:** ```kotlin -@TurboNavGraphDestination(uri = "turbo://fragment/web") +@TurboNavGraphDestination(uri = "hotwire://fragment/web") class WebFragment : TurboWebFragment() ``` @@ -56,7 +56,7 @@ In its simplest form, your native Fragment will look like: **`ImageViewerFragment.kt`:** ```kotlin -@TurboNavGraphDestination(uri = "turbo://fragment/image_viewer") +@TurboNavGraphDestination(uri = "hotwire://fragment/image_viewer") class ImageViewerFragment : TurboFragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.fragment_image_viewer, container, false) @@ -87,7 +87,7 @@ In its simplest form, your web bottom sheet Fragment will look like: **`WebBottomSheetFragment.kt`:** ```kotlin -@TurboNavGraphDestination(uri = "turbo://fragment/web/modal/sheet") +@TurboNavGraphDestination(uri = "hotwire://fragment/web/modal/sheet") class WebBottomSheetFragment : TurboWebBottomSheetDialogFragment() ``` The library automatically inflates a default `R.layout.turbo_fragment_web_bottom_sheet` layout to host a `TurboView`. If you'd like to create your own custom layout for your web bottom sheet Fragment, you can override the `onCreateView()` function and inflate your own layout. diff --git a/docs/NAVIGATION.md b/docs/NAVIGATION.md index 15b725b..a939789 100644 --- a/docs/NAVIGATION.md +++ b/docs/NAVIGATION.md @@ -9,7 +9,7 @@ In your web Fragment, this would look like: **`WebFragment.kt`:** ```kotlin -@TurboNavGraphDestination(uri = "turbo://fragment/web") +@TurboNavGraphDestination(uri = "hotwire://fragment/web") class WebFragment : TurboWebFragment() { // ... @@ -52,7 +52,7 @@ In your Fragment, this would look like: **`WebFragment.kt`:** ```kotlin -@TurboNavGraphDestination(uri = "turbo://fragment/web") +@TurboNavGraphDestination(uri = "hotwire://fragment/web") class WebFragment : TurboWebFragment() { // ... diff --git a/docs/PATH-CONFIGURATION.md b/docs/PATH-CONFIGURATION.md index 5445338..c87d2b4 100644 --- a/docs/PATH-CONFIGURATION.md +++ b/docs/PATH-CONFIGURATION.md @@ -19,7 +19,7 @@ In its simplest form, your JSON configuration will look like: ], "properties": { "context": "default", - "uri": "turbo://fragment/web", + "uri": "hotwire://fragment/web", "pull_to_refresh_enabled": true } } diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/config/HotwireNavigation.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/config/HotwireNavigation.kt index 4176505..0869b0a 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/config/HotwireNavigation.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/config/HotwireNavigation.kt @@ -4,7 +4,7 @@ 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.destinations.HotwireDestination import dev.hotwire.navigation.fragments.HotwireWebBottomSheetFragment import dev.hotwire.navigation.fragments.HotwireWebFragment import dev.hotwire.navigation.routing.AppNavigationRouteDecisionHandler @@ -26,8 +26,8 @@ internal object HotwireNavigation { ) @Suppress("UNCHECKED_CAST") - var registeredBridgeComponentFactories: List>> - get() = Hotwire.config.registeredBridgeComponentFactories as List>> + var registeredBridgeComponentFactories: List>> + get() = Hotwire.config.registeredBridgeComponentFactories as List>> set(value) { Hotwire.config.registeredBridgeComponentFactories = value } } @@ -43,7 +43,7 @@ fun Hotwire.registerRouteDecisionHandlers(decisionHandlers: List>>) { +fun Hotwire.registerBridgeComponents(factories: List>>) { config.registeredBridgeComponentFactories = factories } diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDestination.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDestination.kt index beee101..caa2352 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDestination.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDestination.kt @@ -1,28 +1,183 @@ package dev.hotwire.navigation.destinations -import kotlin.reflect.KClass -import kotlin.reflect.full.findAnnotation +import android.content.Intent +import android.os.Bundle +import androidx.activity.result.ActivityResultLauncher +import androidx.appcompat.widget.Toolbar +import androidx.fragment.app.Fragment +import androidx.navigation.NavOptions +import androidx.navigation.navOptions +import dev.hotwire.core.bridge.BridgeDestination +import dev.hotwire.core.config.Hotwire +import dev.hotwire.core.turbo.config.PathConfigurationProperties +import dev.hotwire.core.turbo.config.context +import dev.hotwire.core.turbo.nav.TurboNavPresentationContext +import dev.hotwire.core.turbo.visit.VisitAction +import dev.hotwire.navigation.R +import dev.hotwire.navigation.activities.HotwireActivity +import dev.hotwire.navigation.config.HotwireNavigation +import dev.hotwire.navigation.fragments.HotwireFragmentDelegate +import dev.hotwire.navigation.fragments.HotwireFragmentViewModel +import dev.hotwire.navigation.navigator.Navigator +import dev.hotwire.navigation.routing.Router /** - * Annotation for each Fragment that will be registered as a navigation destination. - * - * For example: - * `@HotwireDestination(uri = "turbo://fragment/search")` - * `class SearchFragment : TurboWebFragment()` - * - * @property uri The URI to be registered with the Android Navigation component nav graph. + * The primary interface that a navigable Fragment implements to provide the library with + * the information it needs to properly navigate. */ -@Target(AnnotationTarget.CLASS) -@Retention(AnnotationRetention.RUNTIME) -@MustBeDocumented -annotation class HotwireDestination( - val uri: String -) { - companion object { - internal fun from(klass: KClass): HotwireDestination { - return requireNotNull(klass.findAnnotation()) { - "A HotwireDestination annotation is required for the destination: ${klass.simpleName}" +interface HotwireDestination : BridgeDestination { + /** + * Gets the navigator instance associated with this destination. + */ + val navigator: Navigator + + /** + * Gets the fragment instance for this destination. + */ + val fragment: Fragment + get() = this as Fragment + + /** + * Gets the location for this destination. + */ + val location: String + get() = requireNotNull(fragment.arguments?.location) + + /** + * Gets the path configuration properties for the location associated with this + * destination. + */ + val pathProperties: PathConfigurationProperties + get() = Hotwire.config.pathConfiguration.properties(location) + + /** + * Gets the [HotwireFragmentViewModel] associated with this destination. + */ + val fragmentViewModel: HotwireFragmentViewModel + get() = delegate().fragmentViewModel + + /** + * Specifies whether the destination fragment is currently active and + * added to its parent activity. + */ + val isActive: Boolean + get() = fragment.isAdded && !fragment.isDetached + + /** + * Specifies whether the destination was presented in a modal context. + */ + val isModal: Boolean + get() = pathProperties.context == TurboNavPresentationContext.MODAL + + /** + * Gets the delegate instance that handles the Fragment's lifecycle events. + */ + fun delegate(): HotwireFragmentDelegate + + /** + * Returns the [Toolbar] used for navigation by the given view. + */ + fun toolbarForNavigation(): Toolbar? + + /** + * Specifies whether title changes should be automatically observed and update + * the title in the Toolbar provided from toolbarForNavigation(), if available. + * Default is true. + */ + fun shouldObserveTitleChanges(): Boolean { + return true + } + + /** + * Called before any navigation action takes places. This is a useful place + * for state cleanup in your Fragment if necessary. + */ + fun onBeforeNavigation() + + /** + * Refresh the destination's contents. + * + * @param displayProgress Whether progress should be displayed while refreshing. + */ + fun refresh(displayProgress: Boolean = true) + + /** + * Gets the navigator that will be used for navigating to `newLocation`. You should + * not have to override this, unless you're using a [NestedNavigatorHostDelegate] to provide + * sub-navigation within your current Fragment destination and would like custom behavior. + */ + fun navigatorForNavigation(newLocation: String): Navigator { + return navigator + } + + /** + * Determines whether the new location should be routed within in-app navigation from the + * current destination. By default, the registered [Router.RouteDecisionHandler] instances are used to + * determine routing logic. You can override the global behavior for a specific destination, + * but it's recommend to use dedicated [Router.RouteDecisionHandler] instances for routing logic. + */ + fun decideRoute(newLocation: String): Router.Decision { + return HotwireNavigation.router.decideRoute( + location = newLocation, + configuration = navigator.configuration, + activity = fragment.requireActivity() as HotwireActivity + ) + } + + /** + * Gets the default set of navigation options (basic enter/exit animations) for the Android + * Navigation component to use to execute a navigation event. This can be overridden if + * you'd like to provide your own. + */ + fun getNavigationOptions( + newLocation: String, + newPathProperties: PathConfigurationProperties, + action: VisitAction + ): NavOptions { + val modal = newPathProperties.context == TurboNavPresentationContext.MODAL + val replace = action == VisitAction.REPLACE + + return if (modal) { + navOptions { + anim { + enter = if (replace) 0 else R.anim.enter_slide_in_bottom + exit = R.anim.exit_slide_out_bottom + popEnter = R.anim.enter_slide_in_bottom + popExit = R.anim.exit_slide_out_bottom + } + } + } else { + navOptions { + anim { + enter = if (replace) 0 else R.anim.enter_slide_in_right + exit = R.anim.exit_slide_out_left + popEnter = R.anim.enter_slide_in_left + popExit = R.anim.exit_slide_out_right + } } } } + + /** + * Gets a registered activity result launcher instance for the given `requestCode`. + * + * Override to provide your own [androidx.activity.result.ActivityResultLauncher] + * instances. If your app doesn't have a matching `requestCode`, you must call + * `super.activityResultLauncher(requestCode)` to give the Turbo library an + * opportunity to provide a matching result launcher. + * + * @param requestCode The request code for the corresponding result launcher. + */ + fun activityResultLauncher(requestCode: Int): ActivityResultLauncher? { + return null + } + + fun prepareNavigation(onReady: () -> Unit) + + override fun bridgeWebViewIsReady(): Boolean { + return navigator.session.isReady + } + + private val Bundle.location + get() = getString("location") } diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDestinationDeepLink.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDestinationDeepLink.kt new file mode 100644 index 0000000..a6d1923 --- /dev/null +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDestinationDeepLink.kt @@ -0,0 +1,28 @@ +package dev.hotwire.navigation.destinations + +import kotlin.reflect.KClass +import kotlin.reflect.full.findAnnotation + +/** + * Annotation for each Fragment that will be registered as a navigation destination. + * + * For example: + * `@HotwireDestinationDeepLink(uri = "hotwire://fragment/search")` + * `class SearchFragment : HotwireWebFragment()` + * + * @property uri The deeplink URI to be registered with the Android Navigation component nav graph. + */ +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +@MustBeDocumented +annotation class HotwireDestinationDeepLink( + val uri: String +) { + companion object { + internal fun from(klass: KClass): HotwireDestinationDeepLink { + return requireNotNull(klass.findAnnotation()) { + "A HotwireDestinationDeepLink annotation is required for the destination: ${klass.simpleName}" + } + } + } +} diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireNavDialogDestination.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDialogDestination.kt similarity index 84% rename from navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireNavDialogDestination.kt rename to navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDialogDestination.kt index e8ff79c..e734971 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireNavDialogDestination.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDialogDestination.kt @@ -4,6 +4,6 @@ package dev.hotwire.navigation.destinations * The interface that a navigable DialogFragment implements to provide the library with * the information it needs to properly navigate. */ -interface HotwireNavDialogDestination { +interface HotwireDialogDestination { fun closeDialog() } diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireNavDestination.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireNavDestination.kt deleted file mode 100644 index 20a67c0..0000000 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireNavDestination.kt +++ /dev/null @@ -1,183 +0,0 @@ -package dev.hotwire.navigation.destinations - -import android.content.Intent -import android.os.Bundle -import androidx.activity.result.ActivityResultLauncher -import androidx.appcompat.widget.Toolbar -import androidx.fragment.app.Fragment -import androidx.navigation.NavOptions -import androidx.navigation.navOptions -import dev.hotwire.core.bridge.BridgeDestination -import dev.hotwire.core.config.Hotwire -import dev.hotwire.core.turbo.config.PathConfigurationProperties -import dev.hotwire.core.turbo.config.context -import dev.hotwire.core.turbo.nav.TurboNavPresentationContext -import dev.hotwire.core.turbo.visit.VisitAction -import dev.hotwire.navigation.R -import dev.hotwire.navigation.activities.HotwireActivity -import dev.hotwire.navigation.config.HotwireNavigation -import dev.hotwire.navigation.fragments.HotwireFragmentDelegate -import dev.hotwire.navigation.fragments.HotwireFragmentViewModel -import dev.hotwire.navigation.navigator.Navigator -import dev.hotwire.navigation.routing.Router - -/** - * The primary interface that a navigable Fragment implements to provide the library with - * the information it needs to properly navigate. - */ -interface HotwireNavDestination : BridgeDestination { - /** - * Gets the navigator instance associated with this destination. - */ - val navigator: Navigator - - /** - * Gets the fragment instance for this destination. - */ - val fragment: Fragment - get() = this as Fragment - - /** - * Gets the location for this destination. - */ - val location: String - get() = requireNotNull(fragment.arguments?.location) - - /** - * Gets the path configuration properties for the location associated with this - * destination. - */ - val pathProperties: PathConfigurationProperties - get() = Hotwire.config.pathConfiguration.properties(location) - - /** - * Gets the [HotwireFragmentViewModel] associated with this destination. - */ - val fragmentViewModel: HotwireFragmentViewModel - get() = delegate().fragmentViewModel - - /** - * Specifies whether the destination fragment is currently active and - * added to its parent activity. - */ - val isActive: Boolean - get() = fragment.isAdded && !fragment.isDetached - - /** - * Specifies whether the destination was presented in a modal context. - */ - val isModal: Boolean - get() = pathProperties.context == TurboNavPresentationContext.MODAL - - /** - * Gets the delegate instance that handles the Fragment's lifecycle events. - */ - fun delegate(): HotwireFragmentDelegate - - /** - * Returns the [Toolbar] used for navigation by the given view. - */ - fun toolbarForNavigation(): Toolbar? - - /** - * Specifies whether title changes should be automatically observed and update - * the title in the Toolbar provided from toolbarForNavigation(), if available. - * Default is true. - */ - fun shouldObserveTitleChanges(): Boolean { - return true - } - - /** - * Called before any navigation action takes places. This is a useful place - * for state cleanup in your Fragment if necessary. - */ - fun onBeforeNavigation() - - /** - * Refresh the destination's contents. - * - * @param displayProgress Whether progress should be displayed while refreshing. - */ - fun refresh(displayProgress: Boolean = true) - - /** - * Gets the navigator that will be used for navigating to `newLocation`. You should - * not have to override this, unless you're using a [NestedNavigatorHostDelegate] to provide - * sub-navigation within your current Fragment destination and would like custom behavior. - */ - fun navigatorForNavigation(newLocation: String): Navigator { - return navigator - } - - /** - * Determines whether the new location should be routed within in-app navigation from the - * current destination. By default, the registered [Router.RouteDecisionHandler] instances are used to - * determine routing logic. You can override the global behavior for a specific destination, - * but it's recommend to use dedicated [Router.RouteDecisionHandler] instances for routing logic. - */ - fun decideRoute(newLocation: String): Router.Decision { - return HotwireNavigation.router.decideRoute( - location = newLocation, - configuration = navigator.configuration, - activity = fragment.requireActivity() as HotwireActivity - ) - } - - /** - * Gets the default set of navigation options (basic enter/exit animations) for the Android - * Navigation component to use to execute a navigation event. This can be overridden if - * you'd like to provide your own. - */ - fun getNavigationOptions( - newLocation: String, - newPathProperties: PathConfigurationProperties, - action: VisitAction - ): NavOptions { - val modal = newPathProperties.context == TurboNavPresentationContext.MODAL - val replace = action == VisitAction.REPLACE - - return if (modal) { - navOptions { - anim { - enter = if (replace) 0 else R.anim.enter_slide_in_bottom - exit = R.anim.exit_slide_out_bottom - popEnter = R.anim.enter_slide_in_bottom - popExit = R.anim.exit_slide_out_bottom - } - } - } else { - navOptions { - anim { - enter = if (replace) 0 else R.anim.enter_slide_in_right - exit = R.anim.exit_slide_out_left - popEnter = R.anim.enter_slide_in_left - popExit = R.anim.exit_slide_out_right - } - } - } - } - - /** - * Gets a registered activity result launcher instance for the given `requestCode`. - * - * Override to provide your own [androidx.activity.result.ActivityResultLauncher] - * instances. If your app doesn't have a matching `requestCode`, you must call - * `super.activityResultLauncher(requestCode)` to give the Turbo library an - * opportunity to provide a matching result launcher. - * - * @param requestCode The request code for the corresponding result launcher. - */ - fun activityResultLauncher(requestCode: Int): ActivityResultLauncher? { - return null - } - - fun prepareNavigation(onReady: () -> Unit) - - override fun bridgeWebViewIsReady(): Boolean { - return navigator.session.isReady - } - - private val Bundle.location - get() = getString("location") -} diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireBottomSheetFragment.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireBottomSheetFragment.kt index 1f8b7f4..85c5db8 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireBottomSheetFragment.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireBottomSheetFragment.kt @@ -8,8 +8,8 @@ import androidx.appcompat.widget.Toolbar import com.google.android.material.bottomsheet.BottomSheetDialogFragment import dev.hotwire.core.turbo.config.title import dev.hotwire.navigation.R -import dev.hotwire.navigation.destinations.HotwireNavDestination -import dev.hotwire.navigation.destinations.HotwireNavDialogDestination +import dev.hotwire.navigation.destinations.HotwireDestination +import dev.hotwire.navigation.destinations.HotwireDialogDestination import dev.hotwire.navigation.navigator.Navigator import dev.hotwire.navigation.navigator.NavigatorHost @@ -20,7 +20,7 @@ import dev.hotwire.navigation.navigator.NavigatorHost * For web bottom sheet fragments, refer to [HotwireWebBottomSheetFragment]. */ abstract class HotwireBottomSheetFragment : BottomSheetDialogFragment(), - HotwireNavDestination, HotwireNavDialogDestination { + HotwireDestination, HotwireDialogDestination { override lateinit var navigator: Navigator internal lateinit var delegate: HotwireFragmentDelegate @@ -61,7 +61,7 @@ abstract class HotwireBottomSheetFragment : BottomSheetDialogFragment(), * Use [registerForActivityResult] with the appropriate * [androidx.activity.result.contract.ActivityResultContract] and its callback. * - * Turbo provides the [HotwireNavDestination.activityResultLauncher] interface + * Turbo provides the [HotwireDestination.activityResultLauncher] interface * to obtain registered result launchers from any destination. */ @Suppress("DEPRECATION") diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireFragment.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireFragment.kt index 6333cae..fd33d0a 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireFragment.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireFragment.kt @@ -9,7 +9,7 @@ import dev.hotwire.core.turbo.config.context import dev.hotwire.core.turbo.config.title import dev.hotwire.core.turbo.nav.TurboNavPresentationContext import dev.hotwire.navigation.R -import dev.hotwire.navigation.destinations.HotwireNavDestination +import dev.hotwire.navigation.destinations.HotwireDestination import dev.hotwire.navigation.navigator.Navigator import dev.hotwire.navigation.navigator.NavigatorHost import dev.hotwire.navigation.observers.HotwireWindowThemeObserver @@ -21,7 +21,7 @@ import dev.hotwire.navigation.session.SessionModalResult * * For web fragments, refer to [HotwireWebFragment]. */ -abstract class HotwireFragment : Fragment(), HotwireNavDestination { +abstract class HotwireFragment : Fragment(), HotwireDestination { override lateinit var navigator: Navigator internal lateinit var delegate: HotwireFragmentDelegate @@ -66,7 +66,7 @@ abstract class HotwireFragment : Fragment(), HotwireNavDestination { * Use [registerForActivityResult] with the appropriate * [androidx.activity.result.contract.ActivityResultContract] and its callback. * - * Turbo provides the [HotwireNavDestination.activityResultLauncher] interface + * Turbo provides the [HotwireDestination.activityResultLauncher] interface * to obtain registered result launchers from any destination. */ @Suppress("DEPRECATION") diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireFragmentDelegate.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireFragmentDelegate.kt index 05c1083..fbd0e01 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireFragmentDelegate.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireFragmentDelegate.kt @@ -1,7 +1,7 @@ package dev.hotwire.navigation.fragments import dev.hotwire.navigation.logging.logEvent -import dev.hotwire.navigation.destinations.HotwireNavDestination +import dev.hotwire.navigation.destinations.HotwireDestination import dev.hotwire.navigation.session.SessionModalResult import dev.hotwire.navigation.session.SessionViewModel import dev.hotwire.navigation.util.displayBackButton @@ -12,7 +12,7 @@ import dev.hotwire.navigation.util.displayBackButtonAsCloseIcon * to this class. Note: This class should not need to be used directly * from within your app. */ -class HotwireFragmentDelegate(private val navDestination: HotwireNavDestination) { +class HotwireFragmentDelegate(private val navDestination: HotwireDestination) { private val fragment = navDestination.fragment private val location = navDestination.location private val navigator = navDestination.navigator diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebBottomSheetFragment.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebBottomSheetFragment.kt index a5f60ba..5440e6a 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebBottomSheetFragment.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebBottomSheetFragment.kt @@ -15,7 +15,7 @@ import dev.hotwire.core.turbo.views.TurboWebChromeClient import dev.hotwire.core.turbo.views.TurboWebView import dev.hotwire.navigation.R import dev.hotwire.navigation.config.HotwireNavigation -import dev.hotwire.navigation.destinations.HotwireDestination +import dev.hotwire.navigation.destinations.HotwireDestinationDeepLink import dev.hotwire.navigation.views.TurboView /** @@ -24,7 +24,7 @@ import dev.hotwire.navigation.views.TurboView * * For native bottom sheet fragments, refer to [HotwireBottomSheetFragment]. */ -@HotwireDestination(uri = "turbo://fragment/web/modal/sheet") +@HotwireDestinationDeepLink(uri = "hotwire://fragment/web/modal/sheet") open class HotwireWebBottomSheetFragment : HotwireBottomSheetFragment(), HotwireWebFragmentCallback { private lateinit var webDelegate: HotwireWebFragmentDelegate diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragment.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragment.kt index 1f69939..3305282 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragment.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragment.kt @@ -14,7 +14,7 @@ import dev.hotwire.core.turbo.views.TurboWebChromeClient import dev.hotwire.core.turbo.views.TurboWebView import dev.hotwire.navigation.R import dev.hotwire.navigation.config.HotwireNavigation -import dev.hotwire.navigation.destinations.HotwireDestination +import dev.hotwire.navigation.destinations.HotwireDestinationDeepLink import dev.hotwire.navigation.session.SessionModalResult import dev.hotwire.navigation.views.TurboView @@ -24,7 +24,7 @@ import dev.hotwire.navigation.views.TurboView * * For native fragments, refer to [HotwireFragment]. */ -@HotwireDestination(uri = "turbo://fragment/web") +@HotwireDestinationDeepLink(uri = "hotwire://fragment/web") open class HotwireWebFragment : HotwireFragment(), HotwireWebFragmentCallback { private lateinit var webDelegate: HotwireWebFragmentDelegate diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragmentDelegate.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragmentDelegate.kt index 4f93ee5..b4b0514 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragmentDelegate.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragmentDelegate.kt @@ -18,7 +18,7 @@ import dev.hotwire.core.turbo.visit.Visit import dev.hotwire.core.turbo.visit.VisitAction import dev.hotwire.core.turbo.visit.VisitDestination import dev.hotwire.core.turbo.visit.VisitOptions -import dev.hotwire.navigation.destinations.HotwireNavDestination +import dev.hotwire.navigation.destinations.HotwireDestination import dev.hotwire.navigation.session.SessionModalResult import dev.hotwire.navigation.util.dispatcherProvider import dev.hotwire.navigation.views.TurboView @@ -32,7 +32,7 @@ import kotlin.random.Random */ internal class HotwireWebFragmentDelegate( private val delegate: HotwireFragmentDelegate, - private val navDestination: HotwireNavDestination, + private val navDestination: HotwireDestination, private val callback: HotwireWebFragmentCallback ) : SessionCallback, VisitDestination { @@ -129,8 +129,7 @@ internal class HotwireWebFragmentDelegate( } /** - * Should be called by the implementing Fragment during - * [dev.hotwire.core.turbo.nav.HotwireNavDestination.refresh] + * Should be called by the implementing Fragment during [HotwireDestination.refresh]. */ fun refresh(displayProgress: Boolean) { if (webView.url == null) return diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/Navigator.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/Navigator.kt index 59c965a..a819259 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/Navigator.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/Navigator.kt @@ -15,8 +15,8 @@ import dev.hotwire.core.turbo.session.Session import dev.hotwire.core.turbo.visit.VisitAction import dev.hotwire.core.turbo.visit.VisitOptions import dev.hotwire.navigation.config.HotwireNavigation -import dev.hotwire.navigation.destinations.HotwireNavDestination -import dev.hotwire.navigation.destinations.HotwireNavDialogDestination +import dev.hotwire.navigation.destinations.HotwireDestination +import dev.hotwire.navigation.destinations.HotwireDialogDestination import dev.hotwire.navigation.logging.logEvent import dev.hotwire.navigation.routing.Router import dev.hotwire.navigation.util.location @@ -28,10 +28,10 @@ class Navigator( private val navController = host.navController /** - * Retrieves the currently active [HotwireNavDestination] on the backstack. + * Retrieves the currently active [HotwireDestination] on the backstack. */ - val currentDestination: HotwireNavDestination - get() = host.childFragmentManager.primaryNavigationFragment as HotwireNavDestination? + val currentDestination: HotwireDestination + get() = host.childFragmentManager.primaryNavigationFragment as HotwireDestination? ?: throw IllegalStateException("No current destination found in NavigatorHost") /** @@ -74,7 +74,7 @@ class Navigator( fun pop() { navigateWhenReady { val currentFragment = currentDestination.fragment - if (currentFragment is HotwireNavDialogDestination) { + if (currentFragment is HotwireDialogDestination) { currentFragment.closeDialog() } else { navController.popBackStack() @@ -150,7 +150,7 @@ class Navigator( navigateWhenReady { val currentFragment = currentDestination.fragment - if (currentFragment is HotwireNavDialogDestination) { + if (currentFragment is HotwireDialogDestination) { currentFragment.closeDialog() } @@ -251,7 +251,7 @@ class Navigator( ) navigateWhenReady { - val isDialog = currentDestination.fragment is HotwireNavDialogDestination + val isDialog = currentDestination.fragment is HotwireDialogDestination if (isDialog) { // Pop the backstack before sending the modal result, since the // underlying fragment is still active and will receive the diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorGraphBuilder.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorGraphBuilder.kt index e25d2a9..f505966 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorGraphBuilder.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorGraphBuilder.kt @@ -16,7 +16,7 @@ import androidx.navigation.get import dev.hotwire.core.turbo.config.PathConfiguration import dev.hotwire.core.turbo.config.uri import dev.hotwire.navigation.config.HotwireNavigation -import dev.hotwire.navigation.destinations.HotwireDestination +import dev.hotwire.navigation.destinations.HotwireDestinationDeepLink import java.util.UUID import kotlin.reflect.KClass import kotlin.reflect.full.isSubclassOf @@ -40,7 +40,7 @@ internal class NavigatorGraphBuilder( val fragmentDestinations = registeredFragments.map { FragmentDestination( route = currentRoute.also { currentRoute++ }.toString(), - uri = HotwireDestination.from(it).uri.toUri(), + uri = HotwireDestinationDeepLink.from(it).uri.toUri(), kClass = it ) } @@ -94,7 +94,7 @@ internal class NavigatorGraphBuilder( private fun List.startDestination(): FragmentDestination { val startDestinationUri = pathConfiguration.properties(startLocation).uri ?: - HotwireDestination.from(HotwireNavigation.defaultFragmentDestination).uri.toUri() + HotwireDestinationDeepLink.from(HotwireNavigation.defaultFragmentDestination).uri.toUri() return requireNotNull(firstOrNull { it.uri == startDestinationUri }) { "A start Fragment destination was not found for uri: $startDestinationUri" diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorRule.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorRule.kt index 5c7c8d5..fadb999 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorRule.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorRule.kt @@ -21,7 +21,7 @@ import dev.hotwire.core.turbo.nav.TurboNavQueryStringPresentation import dev.hotwire.core.turbo.visit.VisitAction import dev.hotwire.core.turbo.visit.VisitOptions import dev.hotwire.navigation.config.HotwireNavigation -import dev.hotwire.navigation.destinations.HotwireDestination +import dev.hotwire.navigation.destinations.HotwireDestinationDeepLink import dev.hotwire.navigation.session.SessionModalResult import dev.hotwire.navigation.util.location @@ -35,7 +35,7 @@ internal class NavigatorRule( pathConfiguration: PathConfiguration, val controller: NavController ) { - val defaultUri = HotwireDestination.from(HotwireNavigation.defaultFragmentDestination).uri.toUri() + val defaultUri = HotwireDestinationDeepLink.from(HotwireNavigation.defaultFragmentDestination).uri.toUri() // Current destination val previousLocation = controller.previousBackStackEntry.location diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/observers/HotwireWindowThemeObserver.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/observers/HotwireWindowThemeObserver.kt index 4c6e91e..af847ec 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/observers/HotwireWindowThemeObserver.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/observers/HotwireWindowThemeObserver.kt @@ -9,10 +9,10 @@ import android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS import androidx.annotation.RequiresApi import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner -import dev.hotwire.navigation.destinations.HotwireNavDestination +import dev.hotwire.navigation.destinations.HotwireDestination import dev.hotwire.navigation.util.animateColorTo -internal class HotwireWindowThemeObserver(val destination: HotwireNavDestination) : DefaultLifecycleObserver { +internal class HotwireWindowThemeObserver(val destination: HotwireDestination) : DefaultLifecycleObserver { private val window: Window? get() = destination.fragment.activity?.window diff --git a/navigation-fragments/src/test/kotlin/dev/hotwire/navigation/navigator/NavigatorRuleTest.kt b/navigation-fragments/src/test/kotlin/dev/hotwire/navigation/navigator/NavigatorRuleTest.kt index f04b7e1..bee250c 100644 --- a/navigation-fragments/src/test/kotlin/dev/hotwire/navigation/navigator/NavigatorRuleTest.kt +++ b/navigation-fragments/src/test/kotlin/dev/hotwire/navigation/navigator/NavigatorRuleTest.kt @@ -48,9 +48,9 @@ class NavigatorRuleTest { private val webModalDestinationId = 2 private val webHomeDestinationId = 3 - private val webUri = Uri.parse("turbo://fragment/web") - private val webModalUri = Uri.parse("turbo://fragment/web/modal") - private val webHomeUri = Uri.parse("turbo://fragment/web/home") + private val webUri = Uri.parse("hotwire://fragment/web") + private val webModalUri = Uri.parse("hotwire://fragment/web/modal") + private val webHomeUri = Uri.parse("hotwire://fragment/web/home") private val extras = null private val navOptions = navOptions {