Skip to content

Commit ac3204c

Browse files
committed
Render NavigationLink as a clickable native container that pushes its destination
1 parent 0147c72 commit ac3204c

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// AndroidNavigationLink.swift
3+
// AndroidSwiftUI
4+
//
5+
// Created by Alsey Coleman Miller on 7/16/26.
6+
//
7+
8+
import AndroidKit
9+
10+
extension NavigationLink: AndroidPrimitive {
11+
12+
var renderedBody: AnyView {
13+
AnyView(AndroidNavigationLinkContainer(proxy: _NavigationLinkProxy(self)))
14+
}
15+
}
16+
17+
/// Native container for `NavigationLink`. Hosts the link's label as a mounted child inside a
18+
/// clickable container that pushes the destination onto the enclosing `NavigationView`'s stack.
19+
struct AndroidNavigationLinkContainer<Label: View, Destination: View> {
20+
21+
let proxy: _NavigationLinkProxy<Label, Destination>
22+
}
23+
24+
extension AndroidNavigationLinkContainer: ParentView {
25+
26+
var children: [AnyView] {
27+
[AnyView(proxy.label)]
28+
}
29+
}
30+
31+
extension AndroidNavigationLinkContainer: AndroidViewRepresentable {
32+
33+
typealias Coordinator = Void
34+
35+
func makeAndroidView(context: Self.Context) -> AndroidWidget.LinearLayout {
36+
let view = AndroidWidget.LinearLayout(context.androidContext)
37+
let listener = ViewOnClickListener(action: { proxy.activate() })
38+
view.setClickable(true)
39+
view.setOnClickListener(listener.as(AndroidView.View.OnClickListener.self))
40+
return view
41+
}
42+
43+
func updateAndroidView(_ view: AndroidWidget.LinearLayout, context: Self.Context) {
44+
45+
}
46+
}

0 commit comments

Comments
 (0)