From 1387725aabd42e02646899a36a2f76731268191c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwas=CC=81niewski?= Date: Tue, 5 Mar 2024 07:58:47 -0800 Subject: [PATCH] fix: add compiler conditional to hover style (#43331) Summary: Commit https://github.com/facebook/react-native/commit/73664f576aaa472d5c8fb2a02e0ddd017bbb2ea4 broke two jobs in CircleCI that we run using Xcode 14.3.1 because the commit introduced some types that are available only to iOS 17. The code was wrapped around if(available()) statement, but this does not compile out the code. It is a runtime check and the code needs to build anyway. This takes effect at compile time as well. However, unlike with #available, the method must type check and compile. The code will always be emitted into your binary: however, it will only be used when the binary is executed on platforms that meet the availability requirements. source: [forums.swift.org/t/if-vs-available-vs-if-available/40266/2](https://forums.swift.org/t/if-vs-available-vs-if-available/40266/2) This change should fix it, introducing some compile time pragmas that removes the code if we build with older versions of Xcode ## Changelog: [IOS] [ADDED] - Compiler conditionals for hover style (cursor: pointer) Pull Request resolved: https://github.com/facebook/react-native/pull/43331 Test Plan: CI Green Reviewed By: dmytrorykun Differential Revision: D54540520 Pulled By: cipolleschi fbshipit-source-id: 943ac479062e11969efa7645ec0ead26c6866374 --- .../Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm | 2 ++ packages/react-native/React/Views/RCTView.m | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm index 6bdfb69e171a29..8b9f511d89aa57 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm @@ -597,6 +597,7 @@ - (void)invalidateLayer layer.shadowPath = nil; } +#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 /* __IPHONE_17_0 */ // Stage 1.5. Cursor / Hover Effects if (@available(iOS 17.0, *)) { UIHoverStyle *hoverStyle = nil; @@ -621,6 +622,7 @@ - (void)invalidateLayer } [self setHoverStyle:hoverStyle]; } +#endif // Stage 2. Border Rendering const bool useCoreAnimationBorderRendering = diff --git a/packages/react-native/React/Views/RCTView.m b/packages/react-native/React/Views/RCTView.m index 292956e268a723..3a8658100332fe 100644 --- a/packages/react-native/React/Views/RCTView.m +++ b/packages/react-native/React/Views/RCTView.m @@ -896,6 +896,7 @@ static void RCTUpdateShadowPathForView(RCTView *view) static void RCTUpdateHoverStyleForView(RCTView *view) { +#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 /* __IPHONE_17_0 */ if (@available(iOS 17.0, *)) { UIHoverStyle *hoverStyle = nil; if ([view cursor] == RCTCursorPointer) { @@ -917,6 +918,7 @@ static void RCTUpdateHoverStyleForView(RCTView *view) } [view setHoverStyle:hoverStyle]; } +#endif } - (void)updateClippingForLayer:(CALayer *)layer