@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.
@@ -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": container.onScroll = nil
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
- container.onScroll?(["x": Double(offset.x), "y": Double(offset.y)])
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
@@ -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 handler: (Any?) -> Void
226
+ private let throttle: EventThrottle
226
227
 
227
228
  init(handler: @escaping (Any?) -> Void) {
228
- self.handler = handler
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
- handler(payload)
242
+ throttle.fire(payload)
238
243
  }
239
244
  }
240
245
  #endif
@@ -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 handler: (Any?) -> Void
58
- init(handler: @escaping (Any?) -> Void) { self.handler = handler }
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
- handler(Double(slider.value))
65
+ throttle.fire(["value": Double(slider.value)])
61
66
  }
62
67
  }
63
68
  #endif
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thelacanians/vue-native-cli",
3
- "version": "0.4.14",
3
+ "version": "0.4.15",
4
4
  "description": "CLI for creating and running Vue Native apps",
5
5
  "license": "MIT",
6
6
  "author": "Vue Native Contributors",