-
Notifications
You must be signed in to change notification settings - Fork 899
Mobile: Bridge components #2307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+516
−99
Merged
Changes from all commits
Commits
Show all changes
77 commits
Select commit
Hold shift + click to select a range
b84da94
Add Hotwire Native Bridge wiring.
svara 177afe1
Add bridge page controller and helpers.
svara ecf0921
Add bridge page targets.
svara 37f0a2c
Add hotwire-native-bridge vendor js.
svara 2d7b76f
Fix bridge viewport safe-area insets.
svara 367a7ab
Use raw page_title in bridge page title attribute
svara 69c17a7
Add bridge insets controller.
svara cdc4f2c
Wire bridge insets controller into the layout.
svara 367edfc
Add bridge nav-button controller.
svara c61942d
Add bridge form controller.
svara 4cbc2c6
Hide bridged submit button when native form component is active.
svara 58664f8
Add `bridged_form_with` helper for bridge form controller.
svara de10717
Use `bridged_form_with` for board creation form.
svara ce0538d
Move bridge insets controller to bridge/controllers.
svara 75431e0
Hide bridged nav-button elements when native nav component is active.
svara dc9c544
Use bridge nav-button for board settings action.
svara 76eaf32
Add bridge buttons controller.
svara 9331c37
Remove bridge nav-button controller.
svara e2f9989
Remove form related events from bridge page controller.
svara b8bb4cf
Remove option to toggle header visibility from mobile apps in bridge …
svara 37f03fc
Use bridge buttons controller in boards.
svara 0a57e39
Remove redundant url from bridge page change payload.
svara d38c0c9
Add bridge overflow menu controller.
svara 1a46ed3
Hide bridged overflow-menu elements when native is active.
svara 674509b
Update overflow menu controller to send an array of menu items.
svara eae17b8
Merge branch 'main' into mobile/bridge-components
3a43941
Move bridge javascript into existing folder structure
adjogima 45f24d9
Move bridge buttons controller to <body>
adjogima 1028eab
Remove useless shouldLoad
adjogima 0d21efc
Use hidden overflow menu container for board bridge items.
svara 3746774
Remove bridge button metadata from board settings link.
svara 228f65d
Remove change event from bridge page controller.
svara 70853ef
Drop label from bridge button.
svara e286539
Drop name from bridge icon.
svara 8f07ad6
Explicitly send submit button data in bridge form controller.
svara 33fa3a9
Remove unused BridgeElement extensions.
svara 24e4335
Remove the <summary> distinction
adjogima c5bd48a
Remove wrapping div in board header
adjogima f848a49
Use already existing buttons to populate the top nav bar
adjogima 4a798b7
Add bridge overflow menu controller to <body>
adjogima ff7162c
Fix overflow-menu css scope
jayohms 19d16e6
Cleanup bridge components
jayohms e35d3c8
Break up excessively long lines with bridge attributes
jayohms ac45da2
Merge branch 'main' into mobile/bridge-components
jayohms b6aac0b
Introduce a bridge helper to get icon asset urls
jayohms b9dcc3c
Update bridged overflow menu items for settings links
jayohms 2b0c4b4
Send icon urls with buttons and resolve duplicate bridge items on the…
jayohms 8cff72e
Hook up the "Create card" button as a bridge form target
jayohms 2e55f67
Extract filtering for enabled targets so that the index of the target…
jayohms 9ac34f8
Only apply the "Don't/Watch this" bridge target for the text variant …
jayohms b074a11
Update the card perma to support bridge buttonsa and the edit form state
jayohms cf3efce
Move the rest of the visible card perma buttons to the overflow menu
jayohms d5fef48
Merge branch 'main' into mobile/bridge-components
jayohms 05c0cbb
Prevent autofocusing the filter input in drop downs
adjogima caafebb
Extract title to helper
adjogima 43314f7
Move the bridge form controller to the outer container so a cancel ta…
jayohms bd8feea
Fix the form submit css scope
jayohms 82d4fa5
Tweak card footer on perma
adjogima 3d09258
Move dialog focus handling to a stimulus controller
adjogima 6fab121
Merge branch 'main' into mobile/bridge-components
adjogima 450f57e
Fix missing underline on card closure message button
adjogima 4f7cec3
Rename bride page controller to title controller and remove text size…
svara 68d1966
Add bridge text size controller.
svara e5c7965
Fix bottom notch in new card form
adjogima 9dc5151
Set footer height
adjogima 8894382
Save a bit of space in "watch" card
adjogima 3b97b2e
Merge branch 'main' into mobile/bridge-components
adjogima 3cada3c
Merge branch 'main' into mobile/bridge-components
jayohms 600ee87
Merge branch 'main' into mobile/bridge-components
jayohms 44732a3
Move dialog focus handling into the dialog controller
adjogima 5113961
Setup proper focus handling for mobile on the card perma's board picker
adjogima e87dc10
Setup focus handling on touch target's connect callback
adjogima b5985ef
Use private functions for bridge components
jayohms e9ebf8e
Fix bad formatting on bridge page title attr
adjogima a9b873f
Merge branch 'main' into mobile/bridge-components
jayohms cc4e19b
Remove reference to removed controller
jayohms cd6478d
Merge branch 'main' into mobile/bridge-components
jayohms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| module BridgeHelper | ||
| def bridge_icon(name) | ||
| asset_url("#{name}.svg") | ||
| end | ||
| end |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails | ||
| import "@hotwired/turbo-rails" | ||
| import "@hotwired/hotwire-native-bridge" | ||
| import "initializers" | ||
| import "controllers" | ||
|
|
||
| import "lexxy" | ||
| import "@rails/actiontext" | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { BridgeComponent } from "@hotwired/hotwire-native-bridge" | ||
| import { BridgeElement } from "@hotwired/hotwire-native-bridge" | ||
|
|
||
| export default class extends BridgeComponent { | ||
| static component = "buttons" | ||
| static targets = [ "button" ] | ||
|
|
||
| buttonTargetConnected() { | ||
| this.notifyBridgeOfConnect() | ||
| } | ||
|
|
||
| buttonTargetDisconnected() { | ||
| if (!this.#isControllerTearingDown()) { | ||
| this.notifyBridgeOfConnect() | ||
| } | ||
| } | ||
|
|
||
| notifyBridgeOfConnect() { | ||
| const buttons = this.#enabledButtonTargets | ||
| .map((target, index) => { | ||
| const element = new BridgeElement(target) | ||
| return { ...element.getButton(), index } | ||
| }) | ||
|
|
||
| this.send("connect", { buttons }, message => { | ||
| this.#clickButton(message) | ||
| }) | ||
| } | ||
|
|
||
| #clickButton(message) { | ||
| const selectedIndex = message.data.selectedIndex | ||
| this.#enabledButtonTargets[selectedIndex].click() | ||
| } | ||
|
|
||
| get #enabledButtonTargets() { | ||
| return this.buttonTargets | ||
| .filter(target => !target.closest("[data-bridge-disabled]")) | ||
| } | ||
|
|
||
| #isControllerTearingDown() { | ||
| return !document.body.contains(this.element) | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { BridgeComponent } from "@hotwired/hotwire-native-bridge" | ||
| import { BridgeElement } from "@hotwired/hotwire-native-bridge" | ||
|
|
||
| export default class extends BridgeComponent { | ||
| static component = "form" | ||
| static targets = [ "submit", "cancel" ] | ||
| static values = { submitTitle: String } | ||
|
|
||
| submitTargetConnected() { | ||
| this.notifyBridgeOfConnect() | ||
| this.#observeSubmitTarget() | ||
| } | ||
|
|
||
| submitTargetDisconnected() { | ||
| this.notifyBridgeOfDisonnect() | ||
| this.submitObserver?.disconnect() | ||
| } | ||
|
|
||
| notifyBridgeOfConnect() { | ||
| const submitElement = new BridgeElement(this.submitTarget) | ||
| const cancelElement = this.hasCancelTarget ? new BridgeElement(this.cancelTarget) : null | ||
|
|
||
| const submitButton = { title: submitElement.title } | ||
| const cancelButton = cancelElement ? { title: cancelElement.title } : null | ||
|
|
||
| this.send("connect", { submitButton, cancelButton }, message => this.receive(message)) | ||
| } | ||
|
|
||
| receive(message) { | ||
| switch (message.event) { | ||
| case "submit": | ||
| this.submitTarget.click() | ||
| break | ||
| case "cancel": | ||
| this.cancelTarget.click() | ||
| break | ||
| } | ||
| } | ||
|
|
||
| notifyBridgeOfDisonnect() { | ||
| this.send("disconnect") | ||
| } | ||
|
|
||
| submitStart() { | ||
| this.send("submitStart") | ||
| } | ||
|
|
||
| submitEnd() { | ||
| this.send("submitEnd") | ||
| } | ||
|
|
||
| #observeSubmitTarget() { | ||
| this.submitObserver = new MutationObserver(() => { | ||
| this.send(this.submitTarget.disabled ? "submitDisabled" : "submitEnabled") | ||
| }) | ||
|
|
||
| this.submitObserver.observe(this.submitTarget, { | ||
| attributes: true, | ||
| attributeFilter: [ "disabled" ] | ||
| }) | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { BridgeComponent } from "@hotwired/hotwire-native-bridge" | ||
|
|
||
| // Bridge component to control custom safe-area insets from native apps. | ||
| // Sets CSS variables --injected-safe-inset-(top|right|bottom|left). | ||
| export default class extends BridgeComponent { | ||
| static component = "insets" | ||
|
|
||
| connect() { | ||
| super.connect() | ||
| this.notifyBridgeOfConnect() | ||
| } | ||
|
|
||
| disconnect() { | ||
| super.disconnect() | ||
| this.send("disconnect") | ||
| } | ||
|
|
||
| notifyBridgeOfConnect() { | ||
| this.send("connect", {}, message => { | ||
| this.#setInsets(message.data) | ||
| }) | ||
| } | ||
|
|
||
| #setInsets({ top, right, bottom, left }) { | ||
| const root = document.documentElement.style | ||
| root.setProperty("--injected-safe-inset-top", `${top}px`) | ||
| root.setProperty("--injected-safe-inset-right", `${right}px`) | ||
| root.setProperty("--injected-safe-inset-bottom", `${bottom}px`) | ||
| root.setProperty("--injected-safe-inset-left", `${left}px`) | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
app/javascript/controllers/bridge/overflow_menu_controller.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { BridgeComponent } from "@hotwired/hotwire-native-bridge" | ||
| import { BridgeElement } from "@hotwired/hotwire-native-bridge" | ||
|
|
||
| export default class extends BridgeComponent { | ||
| static component = "overflow-menu" | ||
| static targets = [ "item" ] | ||
|
|
||
| itemTargetConnected() { | ||
| this.notifyBridgeOfConnect() | ||
| } | ||
|
|
||
| itemTargetDisconnected() { | ||
| if (!this.#isControllerTearingDown) { | ||
| this.notifyBridgeOfConnect() | ||
| } | ||
| } | ||
|
|
||
| notifyBridgeOfConnect() { | ||
| const items = this.#enabledItemTargets | ||
| .map((target, index) => { | ||
| const element = new BridgeElement(target) | ||
| return { title: element.title, index } | ||
| }) | ||
|
|
||
| this.send("connect", { items }, message => { | ||
| this.#clickItem(message) | ||
| }) | ||
| } | ||
|
|
||
| #clickItem(message) { | ||
| const selectedIndex = message.data.selectedIndex | ||
| this.#enabledItemTargets[selectedIndex].click() | ||
| } | ||
|
|
||
| get #enabledItemTargets() { | ||
| return this.itemTargets | ||
| .filter(target => !target.closest("[data-bridge-disabled]")) | ||
| } | ||
|
|
||
| #isControllerTearingDown() { | ||
| return !document.body.contains(this.element) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes
bridged_form_withbehave differently thanform_within the case of no block -- it would make it render an empty form, rather than just an opening form tag. Is this intentional? If not, I think we could do without this conditional, and always pass&to get the matching behaviour.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@svara do you recall why this conditional was added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was following the
auto_submit_form_withpattern/behaviour.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I suspect that one has that because it's commonly used as an empty form. So it's probably there as a convenience.
I'd be tempted to remove it from this one, since
bridged_form_withis more of a form wrapper, so you'd expect it to behave more like a regularform_with. It's a very minor thing, though!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate the explanation @kevinmcconnell.