-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into anim_replace_root
* main: Fix test Log whether a visit that has started is a page refresh Rename method for consistency with scrolling to anchor proposals Use nullable location reference Check for window.Turbo and add clarifying comment Fix the implementation so it properly works for Turbo 8 refreshes without any flickering. Use Turbo.navigator.location to determine the current location, so it works immediately cold boots and Turbo visits Bump minSdkVersion to 26 in the docs REPLACE_ROOT presentation - popUpTo to controller.graph.id (inclusive) Bump minSdkVersion to 26 Upgrade to SDK 34 and bump dependencies to latest versions Tweak the comment, since not all visit proposals will make it to the app After a form redirect to the same page location, don't replace the existing fragment with a new one for a visit Use the public strada dependency Add the overflow-menu component implementation Add the menu component implementation Configure the strada form path as a modal screen Add the form component implementation Intitial work to tie in Strada support with component examples Improve how debug logging is enabled and how exceptions are logged # Conflicts: # turbo/src/main/kotlin/dev/hotwire/turbo/nav/TurboNavRule.kt
- Loading branch information
Showing
36 changed files
with
629 additions
and
88 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
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 |
---|---|---|
|
@@ -26,7 +26,8 @@ | |
}, | ||
{ | ||
"patterns": [ | ||
"/signin$" | ||
"/signin$", | ||
"/strada-form$" | ||
], | ||
"properties": { | ||
"context": "modal", | ||
|
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
9 changes: 9 additions & 0 deletions
9
demo/src/main/kotlin/dev/hotwire/turbo/demo/strada/BridgeComponentFactories.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,9 @@ | ||
package dev.hotwire.turbo.demo.strada | ||
|
||
import dev.hotwire.strada.BridgeComponentFactory | ||
|
||
val bridgeComponentFactories = listOf( | ||
BridgeComponentFactory("form", ::FormComponent), | ||
BridgeComponentFactory("menu", ::MenuComponent), | ||
BridgeComponentFactory("overflow-menu", ::OverflowMenuComponent) | ||
) |
92 changes: 92 additions & 0 deletions
92
demo/src/main/kotlin/dev/hotwire/turbo/demo/strada/FormComponent.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,92 @@ | ||
package dev.hotwire.turbo.demo.strada | ||
|
||
import android.util.Log | ||
import android.view.LayoutInflater | ||
import android.view.Menu | ||
import android.view.MenuItem | ||
import androidx.appcompat.widget.Toolbar | ||
import androidx.fragment.app.Fragment | ||
import dev.hotwire.strada.BridgeComponent | ||
import dev.hotwire.strada.BridgeDelegate | ||
import dev.hotwire.strada.Message | ||
import dev.hotwire.turbo.demo.R | ||
import dev.hotwire.turbo.demo.base.NavDestination | ||
import dev.hotwire.turbo.demo.databinding.FormComponentSubmitBinding | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Bridge component to display a submit button in the native toolbar, | ||
* which will submit the form on the page when tapped. | ||
*/ | ||
class FormComponent( | ||
name: String, | ||
private val delegate: BridgeDelegate<NavDestination> | ||
) : BridgeComponent<NavDestination>(name, delegate) { | ||
|
||
private val submitButtonItemId = 37 | ||
private var submitMenuItem: MenuItem? = null | ||
private val fragment: Fragment | ||
get() = delegate.destination.fragment | ||
private val toolbar: Toolbar? | ||
get() = fragment.view?.findViewById(R.id.toolbar) | ||
|
||
override fun onReceive(message: Message) { | ||
when (message.event) { | ||
"connect" -> handleConnectEvent(message) | ||
"submitEnabled" -> handleSubmitEnabled() | ||
"submitDisabled" -> handleSubmitDisabled() | ||
else -> Log.w("TurboDemo", "Unknown event for message: $message") | ||
} | ||
} | ||
|
||
private fun handleConnectEvent(message: Message) { | ||
val data = message.data<MessageData>() ?: return | ||
showToolbarButton(data) | ||
} | ||
|
||
private fun handleSubmitEnabled() { | ||
toggleSubmitButton(true) | ||
} | ||
|
||
private fun handleSubmitDisabled() { | ||
toggleSubmitButton(false) | ||
} | ||
|
||
private fun showToolbarButton(data: MessageData) { | ||
val menu = toolbar?.menu ?: return | ||
val inflater = LayoutInflater.from(fragment.requireContext()) | ||
val binding = FormComponentSubmitBinding.inflate(inflater) | ||
val order = 999 // Show as the right-most button | ||
|
||
binding.formSubmit.apply { | ||
text = data.title | ||
setOnClickListener { | ||
performSubmit() | ||
} | ||
} | ||
|
||
menu.removeItem(submitButtonItemId) | ||
submitMenuItem = menu.add(Menu.NONE, submitButtonItemId, order, data.title).apply { | ||
actionView = binding.root | ||
setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS) | ||
} | ||
} | ||
|
||
private fun toggleSubmitButton(enable: Boolean) { | ||
val layout = submitMenuItem?.actionView ?: return | ||
|
||
FormComponentSubmitBinding.bind(layout).apply { | ||
formSubmit.isEnabled = enable | ||
} | ||
} | ||
|
||
private fun performSubmit(): Boolean { | ||
return replyTo("connect") | ||
} | ||
|
||
@Serializable | ||
data class MessageData( | ||
@SerialName("submitTitle") val title: String | ||
) | ||
} |
Oops, something went wrong.