one 2.13.9 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/dev/onejs/one/OneKotlinHostView.kt +53 -14
- package/android/src/main/java/dev/onejs/one/OneNativeSourceKeyedState.kt +23 -0
- package/android/src/main/java/dev/onejs/one/OneNativeSourceViewDispatch.kt +16 -3
- package/dist/cjs/metro-config/getViteMetroPluginOptions.cjs +4 -10
- package/dist/cjs/metro-config/getViteMetroPluginOptions.native.cjs +4 -10
- package/dist/cjs/metro-config/getViteMetroPluginOptions.native.js +4 -10
- package/dist/cjs/metro-config/getViteMetroPluginOptions.native.js.map +1 -1
- package/dist/cjs/platform/native-source/view.native.cjs +4 -4
- package/dist/cjs/platform/native-source/view.native.js +4 -4
- package/dist/cjs/platform/native-source/view.native.js.map +1 -1
- package/dist/cjs/platform/native-source/wire.native.cjs +152 -49
- package/dist/cjs/platform/native-source/wire.native.js +152 -49
- package/dist/cjs/platform/native-source/wire.native.js.map +1 -1
- package/dist/cjs/platform/native-source/wireProps.native.cjs +138 -0
- package/dist/cjs/platform/native-source/wireProps.native.js +140 -0
- package/dist/cjs/platform/native-source/wireProps.native.js.map +1 -0
- package/dist/cjs/platform/swift/index.native.cjs +12 -8
- package/dist/cjs/platform/swift/index.native.js +12 -8
- package/dist/cjs/platform/swift/index.native.js.map +1 -1
- package/dist/cjs/router/useScreens.cjs +1 -1
- package/dist/cjs/router/useScreens.native.cjs +2 -1
- package/dist/cjs/router/useScreens.native.js +2 -1
- package/dist/cjs/router/useScreens.native.js.map +1 -1
- package/dist/esm/metro-config/getViteMetroPluginOptions.mjs +4 -10
- package/dist/esm/metro-config/getViteMetroPluginOptions.mjs.map +1 -1
- package/dist/esm/metro-config/getViteMetroPluginOptions.native.js +4 -10
- package/dist/esm/metro-config/getViteMetroPluginOptions.native.js.map +1 -1
- package/dist/esm/platform/native-source/view.native.js +5 -5
- package/dist/esm/platform/native-source/view.native.js.map +1 -1
- package/dist/esm/platform/native-source/wire.native.js +149 -49
- package/dist/esm/platform/native-source/wire.native.js.map +1 -1
- package/dist/esm/platform/native-source/wireProps.native.js +113 -0
- package/dist/esm/platform/native-source/wireProps.native.js.map +1 -0
- package/dist/esm/platform/swift/index.native.js +13 -9
- package/dist/esm/platform/swift/index.native.js.map +1 -1
- package/dist/esm/router/useScreens.mjs +1 -1
- package/dist/esm/router/useScreens.mjs.map +1 -1
- package/dist/esm/router/useScreens.native.js +2 -1
- package/dist/esm/router/useScreens.native.js.map +1 -1
- package/ios/Generated/OneNativeTabViewView.swift +2 -1
- package/ios/OneNativeComposition.swift +1 -0
- package/ios/OneNativeHostingController.swift +113 -0
- package/ios/OneSwiftHostComponentView.mm +28 -4
- package/ios/OneSwiftHostView.swift +63 -9
- package/ios/OneSwiftPackage.swift +6 -1
- package/package.json +13 -13
- package/src/metro-config/getViteMetroPluginOptions.integration.test.ts +33 -3
- package/src/metro-config/getViteMetroPluginOptions.ts +5 -11
- package/src/native/packedClosure.test.ts +59 -22
- package/src/platform/native-source/view.native.tsx +4 -5
- package/src/platform/native-source/wire.native.ts +108 -26
- package/src/platform/native-source/wireProps.native.test.ts +57 -0
- package/src/platform/native-source/wireProps.native.ts +124 -0
- package/src/platform/swift/index.native.tsx +9 -7
- package/src/platform/swift/types.ts +4 -2
- package/src/router/useScreens.tsx +1 -1
- package/types/metro-config/getViteMetroPluginOptions.d.ts +1 -1
- package/types/metro-config/getViteMetroPluginOptions.d.ts.map +1 -1
- package/types/platform/native-source/view.native.d.ts.map +1 -1
- package/types/platform/native-source/wire.native.d.ts +3 -0
- package/types/platform/native-source/wire.native.d.ts.map +1 -1
- package/types/platform/native-source/wireProps.native.d.ts +15 -0
- package/types/platform/native-source/wireProps.native.d.ts.map +1 -0
- package/types/platform/swift/index.native.d.ts.map +1 -1
- package/types/platform/swift/types.d.ts +4 -1
- package/types/platform/swift/types.d.ts.map +1 -1
|
@@ -165,7 +165,7 @@ private struct ActionTabHook: UIViewRepresentable {
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
//
|
|
168
|
+
// navigation and tab bars follow the scroll view named for their top and bottom edges.
|
|
169
169
|
// SwiftUI names the ScrollViews it draws itself, but a React Native ScrollView is a UIScrollView
|
|
170
170
|
// inside a representable it cannot see, so the page's first scroll view is named on every
|
|
171
171
|
// controller from the page's root up to the tab bar controller.
|
|
@@ -173,6 +173,7 @@ private func nameContentScrollView(of page: UIView, from controller: UIViewContr
|
|
|
173
173
|
guard let scrollView = firstScrollView(in: page) else { return }
|
|
174
174
|
var next: UIViewController? = controller
|
|
175
175
|
while let current = next, current !== tabBarController {
|
|
176
|
+
if current.contentScrollView(for: .top) !== scrollView { current.setContentScrollView(scrollView, for: .top) }
|
|
176
177
|
if current.contentScrollView(for: .bottom) !== scrollView { current.setContentScrollView(scrollView, for: .bottom) }
|
|
177
178
|
next = current.parent
|
|
178
179
|
}
|
|
@@ -438,6 +438,7 @@ private struct OneNativeHostRoot: View {
|
|
|
438
438
|
}
|
|
439
439
|
let regions: SafeAreaRegions = hostingScreenInsets ? .all : []
|
|
440
440
|
if controller?.safeAreaRegions != regions { controller?.safeAreaRegions = regions }
|
|
441
|
+
controller?.forwardsScreenNavigation = hostingScreenInsets
|
|
441
442
|
controller?.attach(to: self)
|
|
442
443
|
propagateActive(controller?.isAttached == true)
|
|
443
444
|
}
|
|
@@ -4,6 +4,15 @@ import UIKit
|
|
|
4
4
|
final class OneNativeHostingController<Content: View>: UIHostingController<Content> {
|
|
5
5
|
var isAttached: Bool { view.superview != nil }
|
|
6
6
|
|
|
7
|
+
// a host that fills its screen is that screen's content, as a hosting controller pushed
|
|
8
|
+
// on a navigation controller is. swiftui writes navigationTitle, toolbar, searchable and
|
|
9
|
+
// the content scroll view onto this controller, which is a child the bar never reads, so
|
|
10
|
+
// they are carried to the screen controller the host sits in.
|
|
11
|
+
var forwardsScreenNavigation = false {
|
|
12
|
+
didSet { if forwardsScreenNavigation != oldValue { updateScreenNavigation() } }
|
|
13
|
+
}
|
|
14
|
+
private var navigationForwarder: OneNativeNavigationItemForwarder?
|
|
15
|
+
|
|
7
16
|
// react native placed the host's box, so by default the hosted view ignores the insets
|
|
8
17
|
// it would inherit from the screen. uikit computes them from where the box sits when it
|
|
9
18
|
// lays out, and a transform moving the box never lays it out again: a control that
|
|
@@ -45,14 +54,118 @@ final class OneNativeHostingController<Content: View>: UIHostingController<Conte
|
|
|
45
54
|
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
46
55
|
host.addSubview(view)
|
|
47
56
|
if parent != nil { didMove(toParent: parent) }
|
|
57
|
+
updateScreenNavigation()
|
|
48
58
|
}
|
|
49
59
|
view.frame = host.bounds
|
|
50
60
|
}
|
|
51
61
|
|
|
52
62
|
func detach() {
|
|
53
63
|
guard isAttached || parent != nil else { return }
|
|
64
|
+
navigationForwarder = nil
|
|
65
|
+
for edge in [NSDirectionalRectEdge.top, .bottom] {
|
|
66
|
+
if let parent, let scroll = contentScrollView(for: edge), parent.contentScrollView(for: edge) === scroll {
|
|
67
|
+
parent.setContentScrollView(nil, for: edge)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
54
70
|
if parent != nil { willMove(toParent: nil) }
|
|
55
71
|
view.removeFromSuperview()
|
|
56
72
|
if parent != nil { removeFromParent() }
|
|
57
73
|
}
|
|
74
|
+
|
|
75
|
+
override func setContentScrollView(_ scrollView: UIScrollView?, for edge: NSDirectionalRectEdge) {
|
|
76
|
+
super.setContentScrollView(scrollView, for: edge)
|
|
77
|
+
if forwardsScreenNavigation { parent?.setContentScrollView(scrollView, for: edge) }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private func updateScreenNavigation() {
|
|
81
|
+
guard forwardsScreenNavigation, let parent else { navigationForwarder = nil; return }
|
|
82
|
+
if navigationForwarder?.target !== parent.navigationItem {
|
|
83
|
+
navigationForwarder = OneNativeNavigationItemForwarder(source: navigationItem, target: parent.navigationItem)
|
|
84
|
+
}
|
|
85
|
+
for edge in [NSDirectionalRectEdge.top, .bottom] {
|
|
86
|
+
if let scroll = contentScrollView(for: edge) { parent.setContentScrollView(scroll, for: edge) }
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// mirrors the fields swiftui set on a hosting controller's item onto its screen's item.
|
|
92
|
+
// the screen's owner (react-native-screens) rewrites its whole item whenever the screen's
|
|
93
|
+
// options change or it reappears, so a field the view declared is put back as soon as
|
|
94
|
+
// anything else writes it: the view's own modifiers own those fields, as they do for a
|
|
95
|
+
// pushed hosting controller. fields the view never set stay with the screen's options.
|
|
96
|
+
final class OneNativeNavigationItemForwarder: NSObject {
|
|
97
|
+
private static let keys: [String] = {
|
|
98
|
+
var keys = [
|
|
99
|
+
"title", "titleView", "prompt", "largeTitleDisplayMode", "style", "hidesBackButton",
|
|
100
|
+
"backButtonTitle", "backButtonDisplayMode", "backBarButtonItem", "backAction",
|
|
101
|
+
"leftItemsSupplementBackButton", "leftBarButtonItems", "rightBarButtonItems",
|
|
102
|
+
"leadingItemGroups", "centerItemGroups", "trailingItemGroups", "pinnedTrailingGroup",
|
|
103
|
+
"customizationIdentifier", "additionalOverflowItems", "titleMenuProvider", "renameDelegate",
|
|
104
|
+
"documentProperties", "searchController", "hidesSearchBarWhenScrolling",
|
|
105
|
+
"preferredSearchBarPlacement", "standardAppearance", "compactAppearance",
|
|
106
|
+
"scrollEdgeAppearance", "compactScrollEdgeAppearance",
|
|
107
|
+
]
|
|
108
|
+
if #available(iOS 26.0, *) {
|
|
109
|
+
keys += [
|
|
110
|
+
"attributedTitle", "subtitle", "attributedSubtitle", "subtitleView", "largeTitle",
|
|
111
|
+
"largeSubtitle", "largeAttributedSubtitle", "largeSubtitleView",
|
|
112
|
+
"searchBarPlacementAllowsToolbarIntegration", "searchBarPlacementAllowsExternalIntegration",
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
return keys
|
|
116
|
+
}()
|
|
117
|
+
|
|
118
|
+
private let source: UINavigationItem
|
|
119
|
+
let target: UINavigationItem
|
|
120
|
+
// the fields the view has written; a field it later resets to the default stays owned,
|
|
121
|
+
// so the reset reaches the screen too.
|
|
122
|
+
private var owned = Set<String>()
|
|
123
|
+
private var applying = false
|
|
124
|
+
|
|
125
|
+
init(source: UINavigationItem, target: UINavigationItem) {
|
|
126
|
+
self.source = source
|
|
127
|
+
self.target = target
|
|
128
|
+
super.init()
|
|
129
|
+
let defaults = UINavigationItem()
|
|
130
|
+
for key in Self.keys {
|
|
131
|
+
let value = source.value(forKey: key) as AnyObject?
|
|
132
|
+
let initial = defaults.value(forKey: key) as AnyObject?
|
|
133
|
+
if !Self.same(value, initial) { owned.insert(key) }
|
|
134
|
+
source.addObserver(self, forKeyPath: key, context: nil)
|
|
135
|
+
target.addObserver(self, forKeyPath: key, context: nil)
|
|
136
|
+
}
|
|
137
|
+
for key in owned { apply(key) }
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
deinit {
|
|
141
|
+
for key in Self.keys {
|
|
142
|
+
source.removeObserver(self, forKeyPath: key)
|
|
143
|
+
target.removeObserver(self, forKeyPath: key)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private static func same(_ a: AnyObject?, _ b: AnyObject?) -> Bool {
|
|
148
|
+
switch (a, b) {
|
|
149
|
+
case (nil, nil): return true
|
|
150
|
+
case let (a?, b?): return a === b || a.isEqual(b)
|
|
151
|
+
case let (a?, nil), let (nil, a?): return (a as? NSArray)?.count == 0
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private func apply(_ key: String) {
|
|
156
|
+
let value = source.value(forKey: key) as AnyObject?
|
|
157
|
+
guard !applying, !Self.same(target.value(forKey: key) as AnyObject?, value) else { return }
|
|
158
|
+
applying = true
|
|
159
|
+
target.setValue(value, forKey: key)
|
|
160
|
+
applying = false
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
override func observeValue(
|
|
164
|
+
forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?,
|
|
165
|
+
context: UnsafeMutableRawPointer?
|
|
166
|
+
) {
|
|
167
|
+
guard let keyPath else { return }
|
|
168
|
+
if (object as AnyObject?) === source { owned.insert(keyPath) }
|
|
169
|
+
if owned.contains(keyPath) { apply(keyPath) }
|
|
170
|
+
}
|
|
58
171
|
}
|
|
@@ -8,6 +8,9 @@ using namespace facebook::react;
|
|
|
8
8
|
|
|
9
9
|
@implementation OneSwiftHostComponentView {
|
|
10
10
|
OneSwiftHostView *_hostView;
|
|
11
|
+
// events raised while no emitter is attached (updateProps runs before
|
|
12
|
+
// updateEventEmitter on a new view), flushed once it is
|
|
13
|
+
NSMutableArray<NSArray<NSString *> *> *_pendingEvents;
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
+ (ComponentDescriptorProvider)componentDescriptorProvider {
|
|
@@ -25,15 +28,36 @@ using namespace facebook::react;
|
|
|
25
28
|
[weakSelf updateMeasuredHeight:height];
|
|
26
29
|
};
|
|
27
30
|
_hostView.onEvent = ^(NSString *name, NSString *args) {
|
|
28
|
-
|
|
29
|
-
if (!strongSelf || !strongSelf->_eventEmitter) return;
|
|
30
|
-
auto emitter = std::static_pointer_cast<const OneSwiftHostEventEmitter>(strongSelf->_eventEmitter);
|
|
31
|
-
emitter->onHostEvent({.name = std::string(name.UTF8String), .args = std::string(args.UTF8String)});
|
|
31
|
+
[weakSelf emitHostEvent:name args:args];
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
return self;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
- (void)emitHostEvent:(NSString *)name args:(NSString *)args {
|
|
38
|
+
if (!_eventEmitter) {
|
|
39
|
+
if (!_pendingEvents) _pendingEvents = [NSMutableArray new];
|
|
40
|
+
[_pendingEvents addObject:@[name, args]];
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
auto emitter = std::static_pointer_cast<const OneSwiftHostEventEmitter>(_eventEmitter);
|
|
44
|
+
emitter->onHostEvent({.name = std::string(name.UTF8String), .args = std::string(args.UTF8String)});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
- (void)updateEventEmitter:(EventEmitter::Shared const &)eventEmitter {
|
|
48
|
+
[super updateEventEmitter:eventEmitter];
|
|
49
|
+
NSArray<NSArray<NSString *> *> *pending = _pendingEvents;
|
|
50
|
+
_pendingEvents = nil;
|
|
51
|
+
for (NSArray<NSString *> *event in pending) [self emitHostEvent:event[0] args:event[1]];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// a recycled view starts over: held props and events belong to the last owner
|
|
55
|
+
- (void)prepareForRecycle {
|
|
56
|
+
_pendingEvents = nil;
|
|
57
|
+
[_hostView dropHeldProps];
|
|
58
|
+
[super prepareForRecycle];
|
|
59
|
+
}
|
|
60
|
+
|
|
37
61
|
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
|
|
38
62
|
const auto &next = *std::static_pointer_cast<const OneSwiftHostProps>(props);
|
|
39
63
|
[_hostView configureWithPackageName:RCTNSStringFromString(next.packageName)
|
|
@@ -7,27 +7,61 @@ private final class SwiftHostModel: ObservableObject {
|
|
|
7
7
|
@Published var contractHash = ""
|
|
8
8
|
@Published var propsText = ""
|
|
9
9
|
@Published var fill = false
|
|
10
|
+
// a typed view's decoded props live here, on the host view, so they outlive
|
|
11
|
+
// every SwiftUI body evaluation; `revision` re-renders after they change
|
|
12
|
+
@Published var revision = 0
|
|
13
|
+
var held: AnyObject?
|
|
14
|
+
var document = ""
|
|
15
|
+
var failure: String?
|
|
16
|
+
var dispatch: OneNativeSourceViewDispatch?
|
|
10
17
|
var onHeight: ((CGFloat) -> Void)?
|
|
11
18
|
var onEvent: ((String, String) -> Void)?
|
|
12
19
|
}
|
|
13
20
|
|
|
14
21
|
// a typed view (`public struct X: View`) from the package's generated dispatch
|
|
15
22
|
@MainActor private func typedView(_ model: SwiftHostModel) -> AnyView {
|
|
16
|
-
let
|
|
17
|
-
|
|
18
|
-
return AnyView(Text("swift view \(model.packageName).\(model.view) is not linked into this app; rebuild it").foregroundStyle(.red))
|
|
19
|
-
}
|
|
20
|
-
let dispatch = type.init()
|
|
21
|
-
guard dispatch.contractHash == model.contractHash else {
|
|
22
|
-
return AnyView(Text("swift view \(model.packageName).\(model.view) changed; rebuild the app").foregroundStyle(.red))
|
|
23
|
+
if let failure = model.failure {
|
|
24
|
+
return AnyView(Text(failure).foregroundStyle(.red))
|
|
23
25
|
}
|
|
26
|
+
guard let dispatch = model.dispatch, let held = model.held else { return AnyView(EmptyView()) }
|
|
24
27
|
do {
|
|
25
|
-
return try dispatch.
|
|
28
|
+
return try dispatch.buildView(held, model.view) { [weak model] name, args in model?.onEvent?(name, args) }
|
|
26
29
|
} catch {
|
|
27
30
|
return AnyView(Text("\(model.view): \(error.localizedDescription)").foregroundStyle(.red))
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
|
|
34
|
+
// applies a props document to the held props. a change that does not follow
|
|
35
|
+
// them is refused, and javascript answers the resync event with every prop.
|
|
36
|
+
@MainActor private func applyDocument(_ model: SwiftHostModel, _ text: String) {
|
|
37
|
+
model.failure = nil
|
|
38
|
+
if model.dispatch == nil {
|
|
39
|
+
let className = "OneNativeSourceViews_\(model.packageName)"
|
|
40
|
+
guard let type = NSClassFromString(className) as? OneNativeSourceViewDispatch.Type else {
|
|
41
|
+
model.failure = "swift view \(model.packageName).\(model.view) is not linked into this app; rebuild it"
|
|
42
|
+
model.revision += 1
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
model.dispatch = type.init()
|
|
46
|
+
}
|
|
47
|
+
guard let dispatch = model.dispatch, dispatch.contractHash == model.contractHash else {
|
|
48
|
+
model.failure = "swift view \(model.packageName).\(model.view) changed; rebuild the app"
|
|
49
|
+
model.revision += 1
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
do {
|
|
53
|
+
if let held = try dispatch.updateView(model.held, model.view, text) {
|
|
54
|
+
model.held = held
|
|
55
|
+
model.revision += 1
|
|
56
|
+
} else {
|
|
57
|
+
model.onEvent?("$resync", "[]")
|
|
58
|
+
}
|
|
59
|
+
} catch {
|
|
60
|
+
model.failure = "\(model.view): \(error.localizedDescription)"
|
|
61
|
+
model.revision += 1
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
31
65
|
private struct SwiftHostContent: View {
|
|
32
66
|
@ObservedObject var model: SwiftHostModel
|
|
33
67
|
let standalone: Bool
|
|
@@ -70,7 +104,15 @@ public final class OneSwiftHostView: OneNativeContainerView {
|
|
|
70
104
|
|
|
71
105
|
required init?(coder: NSCoder) { fatalError("init(coder:) is unavailable") }
|
|
72
106
|
|
|
107
|
+
public func dropHeldProps() {
|
|
108
|
+
model.held = nil
|
|
109
|
+
model.dispatch = nil
|
|
110
|
+
model.document = ""
|
|
111
|
+
model.revision += 1
|
|
112
|
+
}
|
|
113
|
+
|
|
73
114
|
public func configure(packageName: String, view: String, contractHash: String, props: String, fill: Bool) {
|
|
115
|
+
let changed = model.packageName != packageName || model.view != view || model.contractHash != contractHash
|
|
74
116
|
if model.packageName != packageName { model.packageName = packageName }
|
|
75
117
|
if model.view != view { model.view = view }
|
|
76
118
|
if model.contractHash != contractHash { model.contractHash = contractHash }
|
|
@@ -78,6 +120,18 @@ public final class OneSwiftHostView: OneNativeContainerView {
|
|
|
78
120
|
model.fill = fill
|
|
79
121
|
updateHost()
|
|
80
122
|
}
|
|
81
|
-
if
|
|
123
|
+
if view.isEmpty {
|
|
124
|
+
if model.propsText != props { model.propsText = props }
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
if changed {
|
|
128
|
+
model.held = nil
|
|
129
|
+
model.dispatch = nil
|
|
130
|
+
model.document = ""
|
|
131
|
+
}
|
|
132
|
+
// fabric may deliver the same text again; a change document applies once
|
|
133
|
+
if model.document == props { return }
|
|
134
|
+
model.document = props
|
|
135
|
+
applyDocument(model, props)
|
|
82
136
|
}
|
|
83
137
|
}
|
|
@@ -79,11 +79,16 @@ public protocol PeachPackage {
|
|
|
79
79
|
|
|
80
80
|
// a package's typed views (`public struct X: View`), built from the element's
|
|
81
81
|
// props as json text; a callback prop reports its arguments through emit as
|
|
82
|
-
// (prop name, json array)
|
|
82
|
+
// (prop name, json array). a host keeps the decoded props of each view
|
|
83
|
+
// instance: `updateView` applies a props document to them (a full document
|
|
84
|
+
// replaces them, a keyed change document edits them) and returns nil when the
|
|
85
|
+
// change does not follow what is held, so the host asks for a full document.
|
|
83
86
|
@MainActor public protocol OneNativeSourceViewDispatch: AnyObject {
|
|
84
87
|
init()
|
|
85
88
|
var contractHash: String { get }
|
|
86
89
|
func view(_ name: String, _ propsJson: String, _ emit: @escaping (String, String) -> Void) throws -> AnyView
|
|
90
|
+
func updateView(_ held: AnyObject?, _ name: String, _ document: String) throws -> AnyObject?
|
|
91
|
+
func buildView(_ held: AnyObject, _ name: String, _ emit: @escaping (String, String) -> Void) throws -> AnyView
|
|
87
92
|
}
|
|
88
93
|
|
|
89
94
|
extension PeachPackage {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "one",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
4
4
|
"description": "One is a React framework for web, iOS, and Android apps.",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"sideEffects": [
|
|
@@ -282,15 +282,15 @@
|
|
|
282
282
|
"@react-navigation/routers": "8.0.0-alpha.21",
|
|
283
283
|
"@rozenite/middleware": "^2.5.0",
|
|
284
284
|
"@ungap/structured-clone": "^1.2.0",
|
|
285
|
-
"@vxrn/color-scheme": "2.
|
|
286
|
-
"@vxrn/compiler": "2.
|
|
287
|
-
"@vxrn/resolve": "2.
|
|
288
|
-
"@vxrn/tslib-lite": "2.
|
|
289
|
-
"@vxrn/use-isomorphic-layout-effect": "2.
|
|
290
|
-
"@vxrn/utils": "2.
|
|
285
|
+
"@vxrn/color-scheme": "2.14.0",
|
|
286
|
+
"@vxrn/compiler": "2.14.0",
|
|
287
|
+
"@vxrn/resolve": "2.14.0",
|
|
288
|
+
"@vxrn/tslib-lite": "2.14.0",
|
|
289
|
+
"@vxrn/use-isomorphic-layout-effect": "2.14.0",
|
|
290
|
+
"@vxrn/utils": "2.14.0",
|
|
291
291
|
"citty": "^0.1.6",
|
|
292
292
|
"core-js": "^3.38.1",
|
|
293
|
-
"create-vxrn": "2.
|
|
293
|
+
"create-vxrn": "2.14.0",
|
|
294
294
|
"escape-string-regexp": "^5.0.0",
|
|
295
295
|
"fast-deep-equal": "^3.1.3",
|
|
296
296
|
"fast-glob": "^3.3.3",
|
|
@@ -312,7 +312,7 @@
|
|
|
312
312
|
"tsconfig-paths": "^4",
|
|
313
313
|
"use-latest-callback": "^0.3.5",
|
|
314
314
|
"vite": "^8.2.2",
|
|
315
|
-
"vxrn": "2.
|
|
315
|
+
"vxrn": "2.14.0",
|
|
316
316
|
"web-streams-polyfill": "^4.3.0",
|
|
317
317
|
"ws": "^8.21.0",
|
|
318
318
|
"xxhashjs": "^0.2.2"
|
|
@@ -342,7 +342,7 @@
|
|
|
342
342
|
"@babel/types": "^7.28.5",
|
|
343
343
|
"babel-dead-code-elimination": "1.0.10",
|
|
344
344
|
"babel-plugin-module-resolver": "^5.0.2",
|
|
345
|
-
"@vxrn/vite-plugin-metro": "2.
|
|
345
|
+
"@vxrn/vite-plugin-metro": "2.14.0"
|
|
346
346
|
},
|
|
347
347
|
"peerDependenciesMeta": {
|
|
348
348
|
"@react-native/babel-preset": {
|
|
@@ -416,7 +416,7 @@
|
|
|
416
416
|
"@types/react-dom": "^19.3.0",
|
|
417
417
|
"@types/react-test-renderer": "^19.1.0",
|
|
418
418
|
"@types/xxhashjs": "^0.2.4",
|
|
419
|
-
"@vxrn/emitter": "2.
|
|
419
|
+
"@vxrn/emitter": "2.14.0",
|
|
420
420
|
"depcheck": "^1.4.7",
|
|
421
421
|
"esbuild": "^0.25.12",
|
|
422
422
|
"immer": "^10.1.1",
|
|
@@ -444,7 +444,7 @@
|
|
|
444
444
|
"@babel/types": "^7.28.5",
|
|
445
445
|
"babel-dead-code-elimination": "1.0.10",
|
|
446
446
|
"babel-plugin-module-resolver": "^5.0.2",
|
|
447
|
-
"@vxrn/vite-plugin-metro": "2.
|
|
447
|
+
"@vxrn/vite-plugin-metro": "2.14.0"
|
|
448
448
|
},
|
|
449
449
|
"publishConfig": {
|
|
450
450
|
"access": "public"
|
|
@@ -612,7 +612,7 @@
|
|
|
612
612
|
}
|
|
613
613
|
}
|
|
614
614
|
},
|
|
615
|
-
"releaseSourceCommit": "
|
|
615
|
+
"releaseSourceCommit": "283ebc3bc2773b8d31b56b08f4de59dbca26c1d6",
|
|
616
616
|
"repository": {
|
|
617
617
|
"type": "git",
|
|
618
618
|
"url": "git+https://github.com/onejs/one.git",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import os from 'node:os'
|
|
3
3
|
import path from 'node:path'
|
|
4
|
+
import { createRequire } from 'node:module'
|
|
4
5
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
|
5
6
|
import { getViteMetroPluginOptions } from './getViteMetroPluginOptions'
|
|
6
7
|
|
|
@@ -37,9 +38,7 @@ describe('getViteMetroPluginOptions babel-config coexistence', () => {
|
|
|
37
38
|
projectRoot: isolatedApp,
|
|
38
39
|
relativeRouterRoot: 'app',
|
|
39
40
|
})
|
|
40
|
-
).toThrow(
|
|
41
|
-
/Metro requires @vxrn\/vite-plugin-metro and babel-preset-expo in the app.*Install with/
|
|
42
|
-
)
|
|
41
|
+
).toThrow(/Metro requires @vxrn\/vite-plugin-metro in the app.*Install with/)
|
|
43
42
|
} finally {
|
|
44
43
|
fs.rmSync(isolatedApp, { recursive: true, force: true })
|
|
45
44
|
}
|
|
@@ -58,6 +57,37 @@ describe('getViteMetroPluginOptions babel-config coexistence', () => {
|
|
|
58
57
|
expect(opts?.babelConfig?.plugins?.length).toBe(5)
|
|
59
58
|
})
|
|
60
59
|
|
|
60
|
+
it('starts Metro without the unused Expo preset in an isolated app', () => {
|
|
61
|
+
const isolatedApp = fs.mkdtempSync(path.join(os.tmpdir(), 'one-metro-no-expo-'))
|
|
62
|
+
const workspaceRoot = path.resolve(__dirname, '../../../../')
|
|
63
|
+
try {
|
|
64
|
+
fs.writeFileSync(
|
|
65
|
+
path.join(isolatedApp, 'package.json'),
|
|
66
|
+
JSON.stringify({ name: 'tmp' })
|
|
67
|
+
)
|
|
68
|
+
fs.writeFileSync(
|
|
69
|
+
path.join(isolatedApp, 'tsconfig.json'),
|
|
70
|
+
JSON.stringify({ compilerOptions: { paths: {} } })
|
|
71
|
+
)
|
|
72
|
+
for (const name of ['one', '@vxrn/utils', '@vxrn/vite-plugin-metro']) {
|
|
73
|
+
const destination = path.join(isolatedApp, 'node_modules', name)
|
|
74
|
+
fs.mkdirSync(path.dirname(destination), { recursive: true })
|
|
75
|
+
fs.symlinkSync(path.join(workspaceRoot, 'node_modules', name), destination, 'dir')
|
|
76
|
+
}
|
|
77
|
+
expect(() =>
|
|
78
|
+
createRequire(isolatedApp + '/').resolve('babel-preset-expo')
|
|
79
|
+
).toThrow()
|
|
80
|
+
const opts = getViteMetroPluginOptions({
|
|
81
|
+
projectRoot: isolatedApp,
|
|
82
|
+
relativeRouterRoot: 'app',
|
|
83
|
+
})
|
|
84
|
+
expect(opts.oneViteMetroBabelConfig).toBe(true)
|
|
85
|
+
expect(opts.babelConfig?.plugins).toHaveLength(5)
|
|
86
|
+
} finally {
|
|
87
|
+
fs.rmSync(isolatedApp, { recursive: true, force: true })
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
|
|
61
91
|
it('still injects One plugins when the user has a babel.config.cjs', () => {
|
|
62
92
|
const cfgPath = path.join(tmpDir, 'babel.config.cjs')
|
|
63
93
|
fs.writeFileSync(cfgPath, "module.exports = require('one/babel-preset')\n")
|
|
@@ -19,19 +19,13 @@ export function getViteMetroPluginOptions({
|
|
|
19
19
|
Parameters<typeof metroPlugin>[0]
|
|
20
20
|
>['defaultConfigOverrides']
|
|
21
21
|
setupFile?: string | { native?: string; ios?: string; android?: string }
|
|
22
|
-
}): Parameters<typeof metroPlugin>[0] {
|
|
22
|
+
}): NonNullable<Parameters<typeof metroPlugin>[0]> {
|
|
23
23
|
const require = createRequire(projectRoot + '/')
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return false
|
|
28
|
-
} catch {
|
|
29
|
-
return true
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
if (missing.length) {
|
|
24
|
+
try {
|
|
25
|
+
require.resolve('@vxrn/vite-plugin-metro')
|
|
26
|
+
} catch {
|
|
33
27
|
throw new Error(
|
|
34
|
-
`[one] Metro requires
|
|
28
|
+
`[one] Metro requires @vxrn/vite-plugin-metro in the app at ${projectRoot}. Install with your package manager, or remove native.bundler: 'metro' to use One's default native bundler.`
|
|
35
29
|
)
|
|
36
30
|
}
|
|
37
31
|
|
|
@@ -43,7 +43,9 @@ for (const name of readdirSync(tmpdir())) {
|
|
|
43
43
|
}
|
|
44
44
|
const scratchDirs: string[] = []
|
|
45
45
|
function makeScratch(name: string): string {
|
|
46
|
-
const dir = realpathSync(
|
|
46
|
+
const dir = realpathSync(
|
|
47
|
+
mkdtempSync(join(tmpdir(), `one-packed-${name}-${process.pid}-`))
|
|
48
|
+
)
|
|
47
49
|
scratchDirs.push(dir)
|
|
48
50
|
return dir
|
|
49
51
|
}
|
|
@@ -251,7 +253,7 @@ console.log('one/native ok ' + url);
|
|
|
251
253
|
expect(out).not.toContain(workspaceRoot)
|
|
252
254
|
})
|
|
253
255
|
|
|
254
|
-
it('keeps the
|
|
256
|
+
it('keeps the packed closure Expo-free and bundles Metro without an Expo preset', () => {
|
|
255
257
|
const tmp = makeScratch('metro')
|
|
256
258
|
const tarballs = join(tmp, 'tarballs')
|
|
257
259
|
mkdirSync(tarballs)
|
|
@@ -410,25 +412,17 @@ if (!config.dependencies['react-native-nitro-modules']) {
|
|
|
410
412
|
encoding: 'utf8',
|
|
411
413
|
})
|
|
412
414
|
|
|
413
|
-
expect(() =>
|
|
414
|
-
execFileSync(
|
|
415
|
-
process.execPath,
|
|
416
|
-
['-e', "require('./metro.config.cjs').catch((error) => { console.error(error.message); process.exitCode = 1 })"],
|
|
417
|
-
{ cwd: appDir, encoding: 'utf8' }
|
|
418
|
-
)
|
|
419
|
-
).toThrow(/Metro requires babel-preset-expo in the app.*Install with/)
|
|
420
|
-
|
|
421
|
-
const expoPresetVersion = JSON.parse(
|
|
422
|
-
readFileSync(join(workspaceRoot, '../node_modules/babel-preset-expo/package.json'), 'utf8')
|
|
423
|
-
).version
|
|
424
|
-
execFileSync('bun', ['add', '-d', `babel-preset-expo@${expoPresetVersion}`], {
|
|
425
|
-
cwd: appDir,
|
|
426
|
-
encoding: 'utf8',
|
|
427
|
-
timeout: 180_000,
|
|
428
|
-
})
|
|
429
415
|
expect(
|
|
430
416
|
existsSync(join(appDir, 'node_modules', 'babel-preset-expo', 'package.json'))
|
|
431
|
-
).toBe(
|
|
417
|
+
).toBe(false)
|
|
418
|
+
execFileSync(
|
|
419
|
+
process.execPath,
|
|
420
|
+
[
|
|
421
|
+
'-e',
|
|
422
|
+
"require('./metro.config.cjs').catch((error) => { console.error(error.message); process.exitCode = 1 })",
|
|
423
|
+
],
|
|
424
|
+
{ cwd: appDir, encoding: 'utf8' }
|
|
425
|
+
)
|
|
432
426
|
|
|
433
427
|
// the installed package supplies real runtime facades. an app with no local
|
|
434
428
|
// ios prebuild must bundle those same files, without fabricated SDK modules.
|
|
@@ -444,14 +438,21 @@ if (!config.dependencies['react-native-nitro-modules']) {
|
|
|
444
438
|
// keeps only phase lines.
|
|
445
439
|
writeFileSync(
|
|
446
440
|
join(appDir, 'metro-build.cjs'),
|
|
447
|
-
`
|
|
441
|
+
`process.env.ONE_METRO_NATIVE_TRANSFORMS = '1'
|
|
442
|
+
const { loadConfig } = require('metro-config')
|
|
448
443
|
const { runMetro } = require('metro')
|
|
449
444
|
const output = require('metro/private/shared/output/bundle')
|
|
450
445
|
const path = require('node:path')
|
|
446
|
+
const fs = require('node:fs')
|
|
447
|
+
const assert = require('node:assert/strict')
|
|
448
|
+
const formatBundlingError = require('metro/private/lib/formatBundlingError').default
|
|
449
|
+
const { patchMetroServerWithViteConfigAndMetroPluginOptions } = require('@vxrn/vite-plugin-metro')
|
|
450
|
+
const { buildOneBabelPlugins } = require('one/babel-preset')
|
|
451
451
|
const started = Date.now()
|
|
452
452
|
const stamp = () => '+' + ((Date.now() - started) / 1000).toFixed(1) + 's'
|
|
453
453
|
async function build() {
|
|
454
454
|
const config = await loadConfig({ config: 'metro.config.cjs', maxWorkers: 2 })
|
|
455
|
+
assert.equal(config.transformerPath, require.resolve('@vxrn/vite-plugin-metro/transformer/metroNativeWorker'))
|
|
455
456
|
config.reporter = {
|
|
456
457
|
update(event) {
|
|
457
458
|
if (event.type === 'initialize_done') console.log(stamp() + ' haste ready')
|
|
@@ -460,8 +461,43 @@ async function build() {
|
|
|
460
461
|
else if (event.type === 'bundle_build_failed' || event.type === 'initialize_failed') console.log(stamp() + ' failed ' + event.type)
|
|
461
462
|
},
|
|
462
463
|
}
|
|
464
|
+
const syntaxCases = [
|
|
465
|
+
['broken.tsx', '// ascii', '\\n'],
|
|
466
|
+
['broken-unicode.tsx', '// café🙂', '\\n'],
|
|
467
|
+
['broken-crlf.tsx', '// café🙂', '\\r\\n'],
|
|
468
|
+
]
|
|
469
|
+
for (const [filename, heading, newline] of syntaxCases) {
|
|
470
|
+
fs.writeFileSync(filename, [heading, '// second', '// third', 'const greeting = ;', ''].join(newline))
|
|
471
|
+
}
|
|
463
472
|
const server = await runMetro(config, { watch: false })
|
|
473
|
+
// use the same server patch as one's native bundle command.
|
|
474
|
+
patchMetroServerWithViteConfigAndMetroPluginOptions(
|
|
475
|
+
server,
|
|
476
|
+
{ root: process.cwd(), mode: 'development', base: '/', env: {} },
|
|
477
|
+
{
|
|
478
|
+
oneViteMetroBabelConfig: true,
|
|
479
|
+
babelConfig: { plugins: buildOneBabelPlugins({
|
|
480
|
+
projectRoot: process.cwd(), relativeRouterRoot: 'app', includeImportMetaEnv: false,
|
|
481
|
+
}) },
|
|
482
|
+
}
|
|
483
|
+
)
|
|
464
484
|
try {
|
|
485
|
+
for (const [filename] of syntaxCases) {
|
|
486
|
+
let response
|
|
487
|
+
try {
|
|
488
|
+
await output.build(server, {
|
|
489
|
+
entryFile: filename, platform: 'android', dev: true, minify: false,
|
|
490
|
+
})
|
|
491
|
+
} catch (error) {
|
|
492
|
+
response = JSON.parse(JSON.stringify(formatBundlingError(error)))
|
|
493
|
+
}
|
|
494
|
+
assert.equal(response?.type, 'TransformError', JSON.stringify(response))
|
|
495
|
+
assert.equal(response.filename, filename)
|
|
496
|
+
assert.equal(response.lineNumber, 4)
|
|
497
|
+
assert.equal(response.column, 17)
|
|
498
|
+
assert.match(response.message, /Unexpected token/)
|
|
499
|
+
console.log(stamp() + ' Android syntax error location: ' + filename + ':4:17')
|
|
500
|
+
}
|
|
465
501
|
for (const dev of [true, false]) {
|
|
466
502
|
const bundle = await output.build(server, {
|
|
467
503
|
entryFile: 'node_modules/one/metro-entry.js',
|
|
@@ -489,8 +525,9 @@ build().catch(error => { console.error(error); process.exitCode = 1 })
|
|
|
489
525
|
timeout: 180_000,
|
|
490
526
|
})
|
|
491
527
|
for (const dev of ['true', 'false']) {
|
|
492
|
-
expect(readFileSync(join(appDir, `bundle.${dev}.js`)).byteLength)
|
|
493
|
-
|
|
528
|
+
expect(readFileSync(join(appDir, `bundle.${dev}.js`)).byteLength).toBeGreaterThan(
|
|
529
|
+
1_000_000
|
|
530
|
+
)
|
|
494
531
|
}
|
|
495
532
|
})
|
|
496
533
|
|
|
@@ -4,8 +4,8 @@ import NativeKotlinHost from '../specs/OneKotlinHostNativeComponent'
|
|
|
4
4
|
import type { KotlinSourceViewProps } from './viewTypes'
|
|
5
5
|
import {
|
|
6
6
|
decodeNativeSourceCallback,
|
|
7
|
-
encodeNativeSourceProps,
|
|
8
7
|
} from './wire.native'
|
|
8
|
+
import { RESYNC_EVENT, useNativeSourceProps } from './wireProps.native'
|
|
9
9
|
|
|
10
10
|
export type { KotlinSourceViewProps } from './viewTypes'
|
|
11
11
|
|
|
@@ -16,8 +16,8 @@ export function KotlinSourceView({
|
|
|
16
16
|
props,
|
|
17
17
|
wires,
|
|
18
18
|
}: KotlinSourceViewProps) {
|
|
19
|
+
const keyed = useNativeSourceProps(props, wires, view !== '')
|
|
19
20
|
const [contentSize, setContentSize] = useState<{ width: number; height: number }>()
|
|
20
|
-
const encoded = wires ? encodeNativeSourceProps(props, wires.props, wires.structs) : props
|
|
21
21
|
return (
|
|
22
22
|
<View style={props.style} collapsable={false}>
|
|
23
23
|
{/* yoga uses the natural child size while retaining parent flex and stretch. */}
|
|
@@ -26,10 +26,9 @@ export function KotlinSourceView({
|
|
|
26
26
|
source={source}
|
|
27
27
|
view={view}
|
|
28
28
|
contractHash={contractHash}
|
|
29
|
-
props={
|
|
30
|
-
typeof value === 'function' ? true : value
|
|
31
|
-
)}
|
|
29
|
+
props={keyed.text}
|
|
32
30
|
onHostEvent={(event) => {
|
|
31
|
+
if (event.nativeEvent.name === RESYNC_EVENT) return keyed.resync()
|
|
33
32
|
const callback = props[event.nativeEvent.name]
|
|
34
33
|
if (typeof callback === 'function') {
|
|
35
34
|
const args = JSON.parse(event.nativeEvent.args) as unknown[]
|