Last active
January 17, 2022 15:10
-
-
Save stefanceriu/3c21452b7d481ceae41c0ca5f0f5c15d to your computer and use it in GitHub Desktop.
Disable Mac Catalyst 77% app scaling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UINSSceneView+CTX.h | |
// EFClass | |
// | |
// Created by Stefan Ceriu on 28/11/2019. | |
// Copyright © 2019 EF Education First. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSObject (CTX) | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UINSSceneView+CTX.m | |
// EFClass | |
// | |
// Created by Stefan Ceriu on 28/11/2019. | |
// Copyright © 2019 EF Education First. All rights reserved. | |
// | |
#import "UINSSceneView+CTX.h" | |
#import <objc/runtime.h> | |
@implementation NSObject (CTX) | |
+ (void)load | |
{ | |
#if TARGET_OS_MACCATALYST | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
CTXSwizzleInstanceMethod(objc_getClass("UINSSceneView"), NSSelectorFromString(@"scaleFactor"), @selector(ctx_scaleFactor)); | |
}); | |
#endif | |
} | |
- (CGFloat)ctx_scaleFactor | |
{ | |
return 1.0f; | |
} | |
static void CTXSwizzleInstanceMethod(Class class, SEL originalSelector, SEL swizzledSelector) { | |
Method originalMethod = class_getInstanceMethod(class, originalSelector); | |
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); | |
if (class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))) { | |
class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); | |
} else { | |
method_exchangeImplementations(originalMethod, swizzledMethod); | |
} | |
} | |
@end |
Hey, normally you would just drop it into your project but I don’t know how that works in react native.
This seems to have stopped working on macOS 11.3, anyone can confirm?
not work on macOS 11.3
macOS 11.3 has different APIs. I have made my implementation public: OverrideCatalystScaleFactor.swift
Nice! 👌
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! Building a macos app using react-native for ios + Catalyst and I'm wondering how to implement this fix. Any chances to get support on how this fix is being applied?