Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions Classes/Utility/FLEXMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,39 @@ extern BOOL FLEXConstructorsShouldRun(void);
/// A macro to return from the current procedure if we don't want to run constructors
#define FLEX_EXIT_IF_NO_CTORS() if (!FLEXConstructorsShouldRun()) return;

/// Returns a UIScreen instance found through the application's scene context,
/// since +[UIScreen mainScreen] is deprecated in iOS 26.
NS_INLINE UIScreen *FLEXScreen(void) {
UIScreen *fallback = nil;
for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait a second, connectedScenes is only available in iOS 13+. FLEX supports iOS 9. This will crash on anything below iOS 13

if ([scene isKindOfClass:[UIWindowScene class]]) {
UIScreen *screen = ((UIWindowScene *)scene).screen;
if (scene.activationState == UISceneActivationStateForegroundActive) {
return screen;
}
if (!fallback) {
fallback = screen;
}
}
}
if (fallback) {
return fallback;
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
return UIScreen.mainScreen;
#pragma clang diagnostic pop
}

/// Rounds down to the nearest "point" coordinate
NS_INLINE CGFloat FLEXFloor(CGFloat x) {
return floor(UIScreen.mainScreen.scale * (x)) / UIScreen.mainScreen.scale;
CGFloat scale = FLEXScreen().scale;
return floor(scale * (x)) / scale;
}

/// Returns the given number of points in pixels
NS_INLINE CGFloat FLEXPointsToPixels(CGFloat points) {
return points / UIScreen.mainScreen.scale;
return points / FLEXScreen().scale;
}

/// Creates a CGRect with all members rounded down to the nearest "point" coordinate
Expand Down