@applicaster/quick-brick-native-apple 6.9.8-patch.0 → 6.9.8-patch.1

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.
@@ -14,6 +14,7 @@
14
14
 
15
15
  RCT_EXPORT_VIEW_PROPERTY(groupId, NSString);
16
16
  RCT_EXPORT_VIEW_PROPERTY(onPositionUpdated, RCTDirectEventBlock);
17
+ RCT_EXPORT_VIEW_PROPERTY(clipThreshold, NSNumber);
17
18
 
18
19
  @end
19
20
 
@@ -10,16 +10,32 @@ import React
10
10
 
11
11
  public class TrackedComponentView: RCTView {
12
12
  @objc public var onPositionUpdated: RCTDirectEventBlock?
13
+ @objc public var clipThreshold: NSNumber = 0
13
14
 
14
15
  /// Convert the view frame to the window's coordinate system
15
16
  private func getViewFrameInWindow() -> CGRect {
16
17
  convert(bounds, to: window)
17
18
  }
18
19
 
19
- // Check if the view is completely within the window's bounds
20
+ // Check if the view is completely within the window's bounds with a threshold
20
21
  private var isCompletelyVisibleOnScreen: Bool {
21
22
  guard let window else { return false }
22
- return window.bounds.contains(getViewFrameInWindow())
23
+
24
+ guard clipThreshold.intValue > 0 else {
25
+ return window.bounds.contains(getViewFrameInWindow())
26
+ }
27
+
28
+ let fullRect = getViewFrameInWindow()
29
+ let visibleRect = fullRect.intersection(window.bounds)
30
+
31
+ guard !visibleRect.isNull else { return false }
32
+
33
+ let threshold = CGFloat(truncating: clipThreshold)
34
+
35
+ let clippedWidth = fullRect.width - visibleRect.width
36
+ let clippedHeight = fullRect.height - visibleRect.height
37
+
38
+ return clippedWidth <= threshold && clippedHeight <= threshold
23
39
  }
24
40
 
25
41
  deinit {
@@ -46,8 +62,7 @@ public class TrackedComponentView: RCTView {
46
62
  }
47
63
 
48
64
  func startObserver() {
49
- timer = Timer.scheduledTimer(withTimeInterval: 1.0,
50
- repeats: true) { [weak self] _ in
65
+ timer = Timer(timeInterval: 1.0, repeats: true) { [weak self] _ in
51
66
  guard let self else { return }
52
67
  let viewFrameInWindow = getViewFrameInWindow()
53
68
 
@@ -59,6 +74,13 @@ public class TrackedComponentView: RCTView {
59
74
  nil)
60
75
  }
61
76
  }
77
+
78
+ // Known limitation using timers is that they won’t fire when the user is interacting with your app.
79
+ // To avoid this we could manually add timer to the run loop in .common mode
80
+ // See this article: https://www.hackingwithswift.com/articles/117/the-ultimate-guide-to-timer#Working%20with%20runloops
81
+ if let timer {
82
+ RunLoop.current.add(timer, forMode: .common)
83
+ }
62
84
  }
63
85
 
64
86
  func stopObserver() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/quick-brick-native-apple",
3
- "version": "6.9.8-patch.0",
3
+ "version": "6.9.8-patch.1",
4
4
  "description": "iOS and tvOS native code for QuickBrick applications. This package is used to provide native logic for QuickBrick",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"