Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keyboard shortcuts support when using UIKit for Mac (Project Catalyst) #305

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
8 changes: 4 additions & 4 deletions Classes/Manager/FLEXManager+Extensibility.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ + (void)registerFieldNames:(NSArray<NSString *> *)names forTypeEncoding:(NSStrin
#pragma mark - Simulator Shortcuts

- (void)registerSimulatorShortcutWithKey:(NSString *)key modifiers:(UIKeyModifierFlags)modifiers action:(dispatch_block_t)action description:(NSString *)description {
#if TARGET_OS_SIMULATOR
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST || TARGET_CPU_ARM64
[FLEXKeyboardShortcutManager.sharedManager registerSimulatorShortcutWithKey:key modifiers:modifiers action:action description:description allowOverride:YES];
#endif
}

- (void)setSimulatorShortcutsEnabled:(BOOL)simulatorShortcutsEnabled {
#if TARGET_OS_SIMULATOR
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST || TARGET_CPU_ARM64
[FLEXKeyboardShortcutManager.sharedManager setEnabled:simulatorShortcutsEnabled];
#endif
}

- (BOOL)simulatorShortcutsEnabled {
#if TARGET_OS_SIMULATOR
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST || TARGET_CPU_ARM64
return FLEXKeyboardShortcutManager.sharedManager.isEnabled;
#else
return NO;
Expand All @@ -109,7 +109,7 @@ - (BOOL)simulatorShortcutsEnabled {
#pragma mark - Shortcuts Defaults

- (void)registerDefaultSimulatorShortcutWithKey:(NSString *)key modifiers:(UIKeyModifierFlags)modifiers action:(dispatch_block_t)action description:(NSString *)description {
#if TARGET_OS_SIMULATOR
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST || TARGET_CPU_ARM64
// Don't allow override to avoid changing keys registered by the app
[FLEXKeyboardShortcutManager.sharedManager registerSimulatorShortcutWithKey:key modifiers:modifiers action:action description:description allowOverride:NO];
#endif
Expand Down
2 changes: 1 addition & 1 deletion Classes/Utility/Keyboard/FLEXKeyboardHelpViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ - (void)viewDidLoad {
self.textView = [[UITextView alloc] initWithFrame:self.view.bounds];
self.textView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.textView];
#if TARGET_OS_SIMULATOR
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST || TARGET_CPU_ARM64
self.textView.text = FLEXKeyboardShortcutManager.sharedManager.keyboardShortcutsDescription;
#endif
self.textView.backgroundColor = UIColor.blackColor;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Utility/Keyboard/FLEXKeyboardShortcutManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#import <objc/runtime.h>
#import <objc/message.h>

#if TARGET_OS_SIMULATOR
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST || TARGET_CPU_ARM64

@interface UIEvent (UIPhysicalKeyboardEvent)

Expand Down
7 changes: 7 additions & 0 deletions Example/FLEXample-Cocoapods.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
544D11A52819CDE500FED6C9 /* FLEXample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = FLEXample.entitlements; sourceTree = "<group>"; };
92E1E1EECA3F2533E1B8BF35 /* Pods-FLEXample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FLEXample.debug.xcconfig"; path = "Target Support Files/Pods-FLEXample/Pods-FLEXample.debug.xcconfig"; sourceTree = "<group>"; };
BBD699DDBAC5A16D8CFD39AC /* libPods-FLEXample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-FLEXample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
BE1780244AEC542DDB894B08 /* Pods-FLEXample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FLEXample.release.xcconfig"; path = "Target Support Files/Pods-FLEXample/Pods-FLEXample.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -81,6 +82,7 @@
EB0852B7D285AB31D7532049 /* Pods */,
);
sourceTree = "<group>";
usesTabs = 0;
};
C386D6CD2419975A00699085 /* Products */ = {
isa = PBXGroup;
Expand Down Expand Up @@ -120,6 +122,7 @@
C386D6DA2419975B00699085 /* LaunchScreen.storyboard */,
C386D6DD2419975B00699085 /* Info.plist */,
C386D6E32419984700699085 /* FLEXample-Bridging-Header.h */,
544D11A52819CDE500FED6C9 /* FLEXample.entitlements */,
);
path = "Supporting Files";
sourceTree = "<group>";
Expand Down Expand Up @@ -429,6 +432,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = "FLEXample/Supporting Files/FLEXample.entitlements";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"FLEXample/Supporting Files/Preview Content\"";
DEVELOPMENT_TEAM = "";
Expand All @@ -441,6 +445,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.flipboard.flex.FLEXample;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
SWIFT_OBJC_BRIDGING_HEADER = "FLEXample/Supporting Files/FLEXample-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -454,6 +459,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = "FLEXample/Supporting Files/FLEXample.entitlements";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"FLEXample/Supporting Files/Preview Content\"";
DEVELOPMENT_TEAM = "";
Expand All @@ -466,6 +472,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.flipboard.flex.FLEXample;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
SWIFT_OBJC_BRIDGING_HEADER = "FLEXample/Supporting Files/FLEXample-Bridging-Header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
36 changes: 16 additions & 20 deletions Example/FLEXample-SPM.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
544D11A22819CA7D00FED6C9 /* FLEX in Frameworks */ = {isa = PBXBuildFile; productRef = 544D11A12819CA7D00FED6C9 /* FLEX */; };
C386D6D02419975A00699085 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C386D6CF2419975A00699085 /* AppDelegate.swift */; };
C386D6D22419975A00699085 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C386D6D12419975A00699085 /* SceneDelegate.swift */; };
C386D6D62419975B00699085 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C386D6D52419975B00699085 /* Assets.xcassets */; };
Expand All @@ -21,13 +22,14 @@
C386D705241AA61600699085 /* music_library_schema.jpg in Resources */ = {isa = PBXBuildFile; fileRef = C386D703241AA61600699085 /* music_library_schema.jpg */; };
C386D70B241AA67800699085 /* Dog.m in Sources */ = {isa = PBXBuildFile; fileRef = C386D709241AA67800699085 /* Dog.m */; };
C386D70C241AA67800699085 /* Owner.m in Sources */ = {isa = PBXBuildFile; fileRef = C386D70A241AA67800699085 /* Owner.m */; };
C38D96EC2818F306008709D0 /* Reflex in Frameworks */ = {isa = PBXBuildFile; productRef = C38D96EB2818F306008709D0 /* Reflex */; };
C3A67856241AB8AD005A4681 /* MiscNetworkRequests.m in Sources */ = {isa = PBXBuildFile; fileRef = C3A67855241AB8AD005A4681 /* MiscNetworkRequests.m */; };
C3A67858241ADDF7005A4681 /* Commit.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A67857241ADDF7005A4681 /* Commit.swift */; };
C3B3760025B8CDA300AD43AB /* Person.m in Sources */ = {isa = PBXBuildFile; fileRef = C3B375FF25B8CDA300AD43AB /* Person.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
544D11A02819CA5600FED6C9 /* FLEX */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FLEX; path = ..; sourceTree = "<group>"; };
544D11A32819CCC800FED6C9 /* FLEXample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = FLEXample.entitlements; sourceTree = "<group>"; };
BBD699DDBAC5A16D8CFD39AC /* libPods-FLEXample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-FLEXample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
C386D6CC2419975A00699085 /* FLEXample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FLEXample.app; sourceTree = BUILT_PRODUCTS_DIR; };
C386D6CF2419975A00699085 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -62,7 +64,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
C38D96EC2818F306008709D0 /* Reflex in Frameworks */,
544D11A22819CA7D00FED6C9 /* FLEX in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -76,8 +78,10 @@
C3A67853241AB88F005A4681 /* Realm */,
C386D6CD2419975A00699085 /* Products */,
DCEB5037DA3D5C01CB9CEE93 /* Frameworks */,
544D11A02819CA5600FED6C9 /* FLEX */,
);
sourceTree = "<group>";
usesTabs = 0;
};
C386D6CD2419975A00699085 /* Products */ = {
isa = PBXGroup;
Expand Down Expand Up @@ -117,6 +121,7 @@
C386D6DA2419975B00699085 /* LaunchScreen.storyboard */,
C386D6DD2419975B00699085 /* Info.plist */,
C386D6E32419984700699085 /* FLEXample-Bridging-Header.h */,
544D11A32819CCC800FED6C9 /* FLEXample.entitlements */,
);
path = "Supporting Files";
sourceTree = "<group>";
Expand Down Expand Up @@ -183,7 +188,7 @@
);
name = FLEXample;
packageProductDependencies = (
C38D96EB2818F306008709D0 /* Reflex */,
544D11A12819CA7D00FED6C9 /* FLEX */,
);
productName = FLEXample;
productReference = C386D6CC2419975A00699085 /* FLEXample.app */;
Expand Down Expand Up @@ -215,7 +220,6 @@
);
mainGroup = C386D6C32419975A00699085;
packageReferences = (
C38D96EA2818F306008709D0 /* XCRemoteSwiftPackageReference "Reflex" */,
);
productRefGroup = C386D6CD2419975A00699085 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -396,9 +400,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = "FLEXample/Supporting Files/FLEXample.entitlements";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"FLEXample/Supporting Files/Preview Content\"";
DEVELOPMENT_TEAM = S6N2F22V2Z;
DEVELOPMENT_TEAM = "";
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = "FLEXample/Supporting Files/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
Expand All @@ -408,6 +413,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.flipboard.flex.FLEXample;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
SWIFT_OBJC_BRIDGING_HEADER = "FLEXample/Supporting Files/FLEXample-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -420,9 +426,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = "FLEXample/Supporting Files/FLEXample.entitlements";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"FLEXample/Supporting Files/Preview Content\"";
DEVELOPMENT_TEAM = S6N2F22V2Z;
DEVELOPMENT_TEAM = "";
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = "FLEXample/Supporting Files/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
Expand All @@ -432,6 +439,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.flipboard.flex.FLEXample;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
SWIFT_OBJC_BRIDGING_HEADER = "FLEXample/Supporting Files/FLEXample-Bridging-Header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -461,22 +469,10 @@
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
C38D96EA2818F306008709D0 /* XCRemoteSwiftPackageReference "Reflex" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "file:///Users/tanner/Repos/Reflex";
requirement = {
branch = master;
kind = branch;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
C38D96EB2818F306008709D0 /* Reflex */ = {
544D11A12819CA7D00FED6C9 /* FLEX */ = {
isa = XCSwiftPackageProductDependency;
package = C38D96EA2818F306008709D0 /* XCRemoteSwiftPackageReference "Reflex" */;
productName = Reflex;
productName = FLEX;
};
/* End XCSwiftPackageProductDependency section */
};
Expand Down
12 changes: 12 additions & 0 deletions Example/FLEXample/Supporting Files/FLEXample.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.personal-information.photos-library</key>
<true/>
</dict>
</plist>