Skip to content

Commit

Permalink
Wrap in NSPopover, first working version
Browse files Browse the repository at this point in the history
  • Loading branch information
BafS committed May 3, 2016
1 parent 9421b42 commit a2565dd
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 55 deletions.
2 changes: 1 addition & 1 deletion index.osx.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const styles = StyleSheet.create({
},

leftPane: {
marginTop: 26,
marginTop: 10,
padding: 6,
paddingTop: 4,
paddingBottom: 20,
Expand Down
31 changes: 18 additions & 13 deletions osx/MaterialColors.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,22 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = "../node_modules/react-native-desktop/Libraries/Image/RCTImage.xcodeproj"; sourceTree = "<group>"; };
00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = "../node_modules/react-native-desktop/Libraries/Network/RCTNetwork.xcodeproj"; sourceTree = "<group>"; };
00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = ../node_modules/react-native-desktop/Libraries/Image/RCTImage.xcodeproj; sourceTree = "<group>"; };
00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = ../node_modules/react-native-desktop/Libraries/Network/RCTNetwork.xcodeproj; sourceTree = "<group>"; };
00E356EE1AD99517003FC87E /* MaterialColorsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MaterialColorsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
00E356F21AD99517003FC87E /* MaterialColorsTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MaterialColorsTests.m; sourceTree = "<group>"; };
139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTSettings.xcodeproj; path = "../node_modules/react-native-desktop/Libraries/Settings/RCTSettings.xcodeproj"; sourceTree = "<group>"; };
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocket.xcodeproj; path = "../node_modules/react-native-desktop/Libraries/WebSocket/RCTWebSocket.xcodeproj"; sourceTree = "<group>"; };
139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTSettings.xcodeproj; path = ../node_modules/react-native-desktop/Libraries/Settings/RCTSettings.xcodeproj; sourceTree = "<group>"; };
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocket.xcodeproj; path = ../node_modules/react-native-desktop/Libraries/WebSocket/RCTWebSocket.xcodeproj; sourceTree = "<group>"; };
13B07F961A680F5B00A75B9A /* MaterialColors.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MaterialColors.app; sourceTree = BUILT_PRODUCTS_DIR; };
13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = MaterialColors/AppDelegate.h; sourceTree = "<group>"; };
13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = MaterialColors/AppDelegate.m; sourceTree = "<group>"; };
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = MaterialColors/Images.xcassets; sourceTree = "<group>"; };
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = MaterialColors/Info.plist; sourceTree = "<group>"; };
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = MaterialColors/main.m; sourceTree = "<group>"; };
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native-desktop/React/React.xcodeproj"; sourceTree = "<group>"; };
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native-desktop/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native-desktop/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = ../node_modules/react-native-desktop/React/React.xcodeproj; sourceTree = "<group>"; };
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = ../node_modules/react-native-desktop/Libraries/LinkingIOS/RCTLinking.xcodeproj; sourceTree = "<group>"; };
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = ../node_modules/react-native-desktop/Libraries/Text/RCTText.xcodeproj; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -430,6 +430,7 @@
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "../node_modules/react-native-desktop/packager/react-native-xcode.sh";
showEnvVarsInLog = 1;
};
/* End PBXShellScriptBuildPhase section */

Expand Down Expand Up @@ -466,14 +467,16 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
);
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
INFOPLIST_FILE = MaterialColorsTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MaterialColors.app/Contents/MacOS/MaterialColors";
};
Expand All @@ -484,10 +487,12 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
COPY_PHASE_STRIP = NO;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
);
INFOPLIST_FILE = MaterialColorsTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MaterialColors.app/Contents/MacOS/MaterialColors";
};
Expand All @@ -503,7 +508,7 @@
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../node_modules/react-native-desktop/React/**",
);
INFOPLIST_FILE = MaterialColors/Info.plist;
INFOPLIST_FILE = "MaterialColors/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = MaterialColors;
Expand All @@ -519,7 +524,7 @@
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../node_modules/react-native-desktop/React/**",
);
INFOPLIST_FILE = MaterialColors/Info.plist;
INFOPLIST_FILE = "MaterialColors/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = MaterialColors;
Expand Down
2 changes: 1 addition & 1 deletion osx/MaterialColors/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@interface AppDelegate : NSObject <NSApplicationDelegate, NSWindowDelegate>

@property (strong, nonatomic) NSWindow *window;
//@property (strong, nonatomic) NSWindow *window;
@property (nonatomic, readonly) RCTBridge *bridge;

@end
77 changes: 47 additions & 30 deletions osx/MaterialColors/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,54 @@ @interface AppDelegate() <RCTBridgeDelegate>

@implementation AppDelegate

NSMenu *statusItemMenu;
NSStatusItem *statusItem;
NSPopover *popover;
NSViewController *popoverViewController;
NSEvent * popoverTransiencyMonitor;

- (void)statusClicked:(id)sender {
if(popoverTransiencyMonitor == nil) {
[popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];

popoverTransiencyMonitor = [NSEvent addGlobalMonitorForEventsMatchingMask:NSLeftMouseDownMask|NSRightMouseDownMask handler:^(NSEvent* event) { [self statusClicked:sender]; }];
} else {
[NSEvent removeMonitor:popoverTransiencyMonitor];

popoverTransiencyMonitor = nil;

[popover close];
}
}

-(id)init
{
if(self = [super init]) {
NSRect contentSize = NSMakeRect(0, 0, 200, 515); // initial size of main NSWindow

self.window = [[NSWindow alloc] initWithContentRect:contentSize
styleMask:NSTitledWindowMask |NSFullSizeContentViewWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask
backing:NSBackingStoreBuffered
defer:NO];
NSWindowController *windowController = [[NSWindowController alloc] initWithWindow:self.window];
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:(NSSquareStatusItemLength)];
// statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[statusItem setTitle:@"MC"];

[statusItem setTarget:self];

[[self window] setTitleVisibility:NSWindowTitleHidden];
[[self window] setTitlebarAppearsTransparent:YES];
[[self window] setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
statusItem.button.action = @selector(statusClicked:);
// statusItem.doubleAction = @selector(statusClicked:);
statusItem.action = @selector(statusClicked:);

statusItemMenu = [[NSMenu alloc] init];
statusItemMenu.autoenablesItems = NO;
statusItem.target = self;

[windowController setShouldCascadeWindows:NO];
[windowController setWindowFrameAutosaveName:@"MaterialColors"];
popover = [[NSPopover alloc] init];

[windowController showWindow:self.window];
[popover setDelegate:self];

[self setUpApplicationMenu];
[popover setAnimates: NO];
[popover setBehavior: NSPopoverBehaviorApplicationDefined];
// [popover setBehavior: NSPopoverBehaviorTransient];
[popover setContentSize: NSMakeSize(200.0f, 510.0f)];

popoverViewController = [[NSViewController alloc] initWithNibName:@"View" bundle:nil];
}
return self;
}
Expand All @@ -46,9 +73,14 @@ - (void)applicationDidFinishLaunching:(__unused NSNotification *)aNotification
moduleName:@"MaterialColors"
initialProperties:nil];

[popoverViewController setView: rootView];
[popover setContentViewController: popoverViewController];
// [popover becomeFirstResponder];
// [popoverViewController becomeFirstResponder];
[rootView becomeFirstResponder];


[self.window setContentView:rootView];
// [self.window setContentView:rootView];
// [[NSApplication sharedApplication] activateIgnoringOtherApps : YES];
}


Expand All @@ -72,19 +104,4 @@ - (void)loadSourceForBridge:(RCTBridge *)bridge
onComplete:loadCallback];
}


- (void)setUpApplicationMenu
{
NSMenuItem *containerItem = [[NSMenuItem alloc] init];
NSMenu *rootMenu = [[NSMenu alloc] initWithTitle:@"" ];
[containerItem setSubmenu:rootMenu];
[rootMenu addItemWithTitle:@"Quit MaterialColors" action:@selector(terminate:) keyEquivalent:@"q"];
[[NSApp mainMenu] addItem:containerItem];
}

- (id)firstResponder
{
return [self.window firstResponder];
}

@end
16 changes: 8 additions & 8 deletions osx/MaterialColors/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.graphics-design</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015</string>
<string>Copyright © 2016</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>LSUIElement</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>
6 changes: 4 additions & 2 deletions osx/MaterialColors/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
int main(int argc, char * argv[]) {
@autoreleasepool {
NSApplication * application = [NSApplication sharedApplication];
NSMenu *mainMenu = [[NSMenu alloc] initWithTitle:@"MaterialColors"];
[NSApp setMainMenu:mainMenu];
[[NSApplication sharedApplication] activateIgnoringOtherApps : YES];
// [[NSUserDefaults standardUserDefaults] boolForKey: NO]; /////
// NSMenu *mainMenu = [[NSMenu alloc] initWithTitle:@"MaterialColors"];
// [NSApp setMainMenu:mainMenu];
AppDelegate * appDelegate = [[AppDelegate alloc] init];
[application setDelegate:appDelegate];
[application run];
Expand Down

0 comments on commit a2565dd

Please sign in to comment.