Skip to content

Commit

Permalink
make notch detection more future proof
Browse files Browse the repository at this point in the history
Summary:
## Changelog:
[Internal] - make notch detection more future proof

current implementation of `isIPhoneX_deprecated` is not completely correct and is already 2 iphones behind. i update the implementation so we don't have to change it with every new iphone that comes out.

Differential Revision: D48254737

fbshipit-source-id: a7c98961f17f3db8c3deb4d358c77f2f0c23200e
  • Loading branch information
philIip authored and facebook-github-bot committed Aug 11, 2023
1 parent 30e2345 commit 2253cb3
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions packages/react-native/React/CoreModules/RCTDeviceInfo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,18 @@ - (void)initialize
object:nil];
}

static BOOL RCTIsIPhoneX()
static BOOL RCTIsIPhoneNotched()
{
static BOOL isIPhoneX = NO;
static BOOL isIPhoneNotched = NO;
static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{
RCTAssertMainQueue();

CGSize screenSize = [UIScreen mainScreen].nativeBounds.size;
CGSize iPhoneXScreenSize = CGSizeMake(1125, 2436);
CGSize iPhoneXMaxScreenSize = CGSizeMake(1242, 2688);
CGSize iPhoneXRScreenSize = CGSizeMake(828, 1792);
CGSize iPhone12ScreenSize = CGSizeMake(1170, 2532);
CGSize iPhone12MiniScreenSize = CGSizeMake(1080, 2340);
CGSize iPhone12ProMaxScreenSize = CGSizeMake(1284, 2778);

isIPhoneX = CGSizeEqualToSize(screenSize, iPhoneXScreenSize) ||
CGSizeEqualToSize(screenSize, iPhoneXMaxScreenSize) || CGSizeEqualToSize(screenSize, iPhoneXRScreenSize) ||
CGSizeEqualToSize(screenSize, iPhone12ScreenSize) || CGSizeEqualToSize(screenSize, iPhone12MiniScreenSize) ||
CGSizeEqualToSize(screenSize, iPhone12ProMaxScreenSize);
;
isIPhoneNotched = RCTSharedApplication().keyWindow.safeAreaInsets.top > 20;
});

return isIPhoneX;
return isIPhoneNotched;
}

static NSDictionary *RCTExportedDimensions(RCTModuleRegistry *moduleRegistry, RCTBridge *bridge)
Expand Down Expand Up @@ -142,7 +130,7 @@ static BOOL RCTIsIPhoneX()
// This prop is deprecated and will be removed in a future release.
// Please use this only for a quick and temporary solution.
// Use <SafeAreaView> instead.
@"isIPhoneX_deprecated" : @(RCTIsIPhoneX()),
@"isIPhoneX_deprecated" : @(RCTIsIPhoneNotched()),
};
});

Expand Down

0 comments on commit 2253cb3

Please sign in to comment.