@thelacanians/vue-native-cli 0.4.14 → 0.4.15
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/dist/cli.js +466 -191
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Bridge/NativeBridge.kt +38 -5
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VListFactory.kt +33 -13
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VScrollViewFactory.kt +27 -6
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VSliderFactory.kt +9 -2
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Helpers/EventThrottle.kt +57 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/EventThrottle.swift +79 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/NativeBridge.swift +106 -112
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VListFactory.swift +19 -2
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VScrollViewFactory.swift +9 -4
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VSliderFactory.swift +8 -3
- package/package.json +1 -1
package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VListFactory.swift
CHANGED
|
@@ -37,6 +37,7 @@ final class VListFactory: NativeComponentFactory {
|
|
|
37
37
|
switch event {
|
|
38
38
|
case "scroll":
|
|
39
39
|
container.onScroll = handler
|
|
40
|
+
container.scrollThrottle = EventThrottle(interval: 0.016, handler: handler)
|
|
40
41
|
case "endReached":
|
|
41
42
|
container.onEndReached = handler
|
|
42
43
|
default:
|
|
@@ -47,7 +48,9 @@ final class VListFactory: NativeComponentFactory {
|
|
|
47
48
|
func removeEventListener(view: UIView, event: String) {
|
|
48
49
|
guard let container = view as? VListContainerView else { return }
|
|
49
50
|
switch event {
|
|
50
|
-
case "scroll":
|
|
51
|
+
case "scroll":
|
|
52
|
+
container.onScroll = nil
|
|
53
|
+
container.scrollThrottle = nil
|
|
51
54
|
case "endReached": container.onEndReached = nil
|
|
52
55
|
default: break
|
|
53
56
|
}
|
|
@@ -106,6 +109,7 @@ final class VListContainerView: UIView {
|
|
|
106
109
|
var itemViews: [UIView] = []
|
|
107
110
|
var estimatedItemHeight: CGFloat = 44
|
|
108
111
|
var onScroll: ((Any?) -> Void)?
|
|
112
|
+
var scrollThrottle: EventThrottle?
|
|
109
113
|
var onEndReached: ((Any?) -> Void)?
|
|
110
114
|
fileprivate var firedEndReached = false
|
|
111
115
|
private lazy var internalDelegate = VListInternalDelegate(container: self)
|
|
@@ -195,7 +199,20 @@ private final class VListInternalDelegate: NSObject,
|
|
|
195
199
|
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
|
196
200
|
guard let container = container else { return }
|
|
197
201
|
let offset = scrollView.contentOffset
|
|
198
|
-
|
|
202
|
+
let payload: [String: Any] = [
|
|
203
|
+
"x": Double(offset.x),
|
|
204
|
+
"y": Double(offset.y),
|
|
205
|
+
"contentWidth": Double(scrollView.contentSize.width),
|
|
206
|
+
"contentHeight": Double(scrollView.contentSize.height),
|
|
207
|
+
"layoutWidth": Double(scrollView.frame.width),
|
|
208
|
+
"layoutHeight": Double(scrollView.frame.height),
|
|
209
|
+
]
|
|
210
|
+
// Use throttle if available, otherwise fire directly
|
|
211
|
+
if let throttle = container.scrollThrottle {
|
|
212
|
+
throttle.fire(payload)
|
|
213
|
+
} else {
|
|
214
|
+
container.onScroll?(payload)
|
|
215
|
+
}
|
|
199
216
|
|
|
200
217
|
// endReached detection (threshold = 20% from bottom)
|
|
201
218
|
let contentH = scrollView.contentSize.height
|
package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VScrollViewFactory.swift
CHANGED
|
@@ -221,20 +221,25 @@ private final class RefreshTarget: NSObject {
|
|
|
221
221
|
// MARK: - ScrollDelegateProxy
|
|
222
222
|
|
|
223
223
|
/// UIScrollViewDelegate proxy that forwards scroll events to a JS handler.
|
|
224
|
+
/// Uses EventThrottle to limit bridge round-trips to ~60/s during fast scrolling.
|
|
224
225
|
private final class ScrollDelegateProxy: NSObject, UIScrollViewDelegate {
|
|
225
|
-
private let
|
|
226
|
+
private let throttle: EventThrottle
|
|
226
227
|
|
|
227
228
|
init(handler: @escaping (Any?) -> Void) {
|
|
228
|
-
self.
|
|
229
|
+
self.throttle = EventThrottle(interval: 0.016, handler: handler)
|
|
229
230
|
super.init()
|
|
230
231
|
}
|
|
231
232
|
|
|
232
233
|
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
|
233
234
|
let payload: [String: Any] = [
|
|
234
235
|
"x": scrollView.contentOffset.x,
|
|
235
|
-
"y": scrollView.contentOffset.y
|
|
236
|
+
"y": scrollView.contentOffset.y,
|
|
237
|
+
"contentWidth": scrollView.contentSize.width,
|
|
238
|
+
"contentHeight": scrollView.contentSize.height,
|
|
239
|
+
"layoutWidth": scrollView.frame.width,
|
|
240
|
+
"layoutHeight": scrollView.frame.height,
|
|
236
241
|
]
|
|
237
|
-
|
|
242
|
+
throttle.fire(payload)
|
|
238
243
|
}
|
|
239
244
|
}
|
|
240
245
|
#endif
|
package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VSliderFactory.swift
CHANGED
|
@@ -53,11 +53,16 @@ final class VSliderFactory: NativeComponentFactory {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/// Throttled target for UISlider .valueChanged events.
|
|
57
|
+
/// Limits bridge round-trips to ~60/s during continuous slider dragging.
|
|
56
58
|
private final class SliderTarget: NSObject {
|
|
57
|
-
let
|
|
58
|
-
init(handler: @escaping (Any?) -> Void) {
|
|
59
|
+
private let throttle: EventThrottle
|
|
60
|
+
init(handler: @escaping (Any?) -> Void) {
|
|
61
|
+
self.throttle = EventThrottle(interval: 0.016, handler: handler)
|
|
62
|
+
super.init()
|
|
63
|
+
}
|
|
59
64
|
@objc func handleValueChanged(_ slider: UISlider) {
|
|
60
|
-
|
|
65
|
+
throttle.fire(["value": Double(slider.value)])
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
68
|
#endif
|