Skip to content
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

Remove phx-replace and replace with data-phx-link-state #1492

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- LiveViewNative.SwiftUI.Client
- `NavigationLink` can perform a replace navigation by adding the `phx-replace` attribute
- `NavigationLink` can perform a replace navigation by setting the `data-phx-link-state` attribute to `replace`
- `NavigationLink` takes a `destination` template to customize the connecting phase View for its navigation event.

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ private let logger = Logger(subsystem: "LiveViewNative", category: "NavigationLi
/// </NavigationLink>
/// ```
///
/// Use the `phx-replace` attribute to do a replace navigation instead of a push.
/// Use the `data-phx-link-state` attribute to do a `replace` navigation instead of a `push`.
/// This will replace the current route with the destination.
///
/// ```html
/// <NavigationLink phx-replace destination={"/products/#{@product.id}"}>
/// <NavigationLink data-phx-link-state="replace" destination={"/products/#{@product.id}"}>
/// <Text>More Information</Text>
/// </NavigationLink>
/// ```
Expand Down Expand Up @@ -57,8 +57,13 @@ struct NavigationLink<Root: RootRegistry>: View {
@_documentation(visibility: public)
private var destination: String?

@LiveAttribute("phx-replace")
private var replace: Bool = false
@LiveAttribute("data-phx-link-state")
private var linkState: LinkState = .push

enum LinkState: String, AttributeDecodable {
case push
case replace
}

@LiveElementIgnored
@Environment(\._anyNavigationTransition)
Expand All @@ -82,7 +87,8 @@ struct NavigationLink<Root: RootRegistry>: View {
} else {
nil
}
if replace {
switch linkState {
case .replace:
SwiftUI.Button {
Task { @MainActor in
try await $liveElement.context.coordinator.session.redirect(
Expand All @@ -98,7 +104,7 @@ struct NavigationLink<Root: RootRegistry>: View {
} label: {
$liveElement.children()
}
} else {
case .push:
SwiftUI.NavigationLink(
value: LiveNavigationEntry(
url: url,
Expand Down
Loading