Purchasely / Purchasely-ReactNative

Other
13 stars 2 forks source link

Make 4.4.0 compile on tvOS #125

Open etiennelab opened 1 month ago

etiennelab commented 1 month ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-purchasely@4.4.0 for the project I'm working on.

In our react-native project, we use the tv fork of react-native (react-native-tvos) to handle Android TV and tvOS since it's not maintained anymore in the main repo. We also use your product Purchasely, and its react native lib. In the podspec, it indicates it's available in tvos (s.tvos.deployment_target = '11.0'), but in the last version, there's an #available check only for iOS but not tvOS. This PR fixes the build issue for tvOS.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-purchasely/ios/PurchaselyView.swift b/node_modules/react-native-purchasely/ios/PurchaselyView.swift
index 16d9a38..9a93e6b 100644
--- a/node_modules/react-native-purchasely/ios/PurchaselyView.swift
+++ b/node_modules/react-native-purchasely/ios/PurchaselyView.swift
@@ -43,12 +43,20 @@ class PurchaselyView: UIView {
     let view = _controller?.view ?? UIView()
     self.addSubview(view)

-      var statusBarHeight: CGFloat = 0.0
-      if #available(iOS 13.0, *) {
-          statusBarHeight = UIApplication.shared.windows.first?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0.0
-      } else {
-          statusBarHeight = UIApplication.shared.statusBarFrame.height
-      }
+    var statusBarHeight: CGFloat = 0.0
+#if TARGET_OS_IOS
+    if #available(iOS 13.0, *) {
+        statusBarHeight = UIApplication.shared.windows.first?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0.0
+    } else {
+        statusBarHeight = UIApplication.shared.statusBarFrame.height
+    }
+#elseif TARGET_OS_TV
+    if #available(tvOS 13.0, *) {
+        statusBarHeight = UIApplication.shared.windows.first?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0.0
+    } else {
+        statusBarHeight = UIApplication.shared.statusBarFrame.height
+    }
+#endif

     view.translatesAutoresizingMaskIntoConstraints = false
     NSLayoutConstraint.activate([

This issue body was partially generated by patch-package.

EPIKorial commented 1 month ago

Hello @etiennelab,

Thank you so much for reaching out to us about this issue. We greatly appreciate and value our customers' feedback!

I apologize for the inconvenience you encountered, but it looks like you managed to solve it effectively—congratulations!

Your suggested fix is indeed relevant. May I suggest the following adjustment ? (Since the code is basically the same)

var statusBarHeight: CGFloat = 0.0
if #available(iOS 13.0, tvOS 13.0, *) {
          statusBarHeight = UIApplication.shared.windows.first?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0.0
      } else {
          statusBarHeight = UIApplication.shared.statusBarFrame.height
      }

Would it work the same for you?

We will integrate this fix into our next release, which should arrive soon. We will notify our customers as soon as it goes live, so stay tuned.

Thanks again for your feedback and assistance with this matter.

Best regards,
Florian

etiennelab commented 1 month ago

Thanks @EPIKorial, of course it is way more concise and readable !

Looking forward to the next release,

Etienne