Skip to content

Commit

Permalink
fix: add compiler conditional to hover style (#43331)
Browse files Browse the repository at this point in the history
Summary:
Commit 73664f5 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: #43331

Test Plan: CI Green

Reviewed By: dmytrorykun

Differential Revision: D54540520

Pulled By: cipolleschi

fbshipit-source-id: 943ac479062e11969efa7645ec0ead26c6866374
  • Loading branch information
okwasniewski authored and facebook-github-bot committed Mar 5, 2024
1 parent 8769245 commit 1387725
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -621,6 +622,7 @@ - (void)invalidateLayer
}
[self setHoverStyle:hoverStyle];
}
#endif

// Stage 2. Border Rendering
const bool useCoreAnimationBorderRendering =
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/React/Views/RCTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -917,6 +918,7 @@ static void RCTUpdateHoverStyleForView(RCTView *view)
}
[view setHoverStyle:hoverStyle];
}
#endif
}

- (void)updateClippingForLayer:(CALayer *)layer
Expand Down

0 comments on commit 1387725

Please sign in to comment.