react-native-nswindow 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,23 +11,23 @@ using WindowProps = NativeNSWindowWindowProps<
11
11
  std::optional<double>, std::optional<double>, std::optional<double>,
12
12
  std::optional<double>, std::optional<double>, std::optional<bool>,
13
13
  std::optional<std::string>, std::optional<std::string>,
14
- std::optional<std::string>, std::optional<std::string>, std::optional<bool>,
14
+ std::optional<std::string>, std::optional<bool>, std::optional<bool>,
15
15
  std::optional<bool>, std::optional<bool>, std::optional<bool>,
16
16
  std::optional<bool>, std::optional<bool>, std::optional<bool>,
17
- std::optional<bool>, std::optional<std::string>, std::optional<bool>,
18
- std::optional<bool>, std::optional<std::string>, std::optional<bool>,
19
- std::string, std::string, jsi::Object>;
17
+ std::optional<std::string>, std::optional<bool>, std::optional<bool>,
18
+ std::optional<std::string>, std::optional<bool>, std::string, std::string,
19
+ jsi::Object>;
20
20
 
21
21
  using ModifyProps = NativeNSWindowModifyableWindowProps<
22
22
  std::optional<double>, std::optional<double>, std::optional<double>,
23
23
  std::optional<double>, std::optional<double>, std::optional<double>,
24
24
  std::optional<double>, std::optional<double>, std::optional<bool>,
25
25
  std::optional<std::string>, std::optional<std::string>,
26
- std::optional<std::string>, std::optional<std::string>, std::optional<bool>,
26
+ std::optional<std::string>, std::optional<bool>, std::optional<bool>,
27
27
  std::optional<bool>, std::optional<bool>, std::optional<bool>,
28
28
  std::optional<bool>, std::optional<bool>, std::optional<bool>,
29
- std::optional<bool>, std::optional<std::string>, std::optional<bool>,
30
- std::optional<bool>, std::optional<std::string>, std::optional<bool>>;
29
+ std::optional<std::string>, std::optional<bool>, std::optional<bool>,
30
+ std::optional<std::string>, std::optional<bool>>;
31
31
 
32
32
  // Concrete types for events
33
33
  using WindowMovePayload =
@@ -1,6 +1,7 @@
1
1
  #import "RNNSWindow.h"
2
2
  #import "RNNSWindowHelper.h"
3
3
  #import <React/RCTConvert.h>
4
+ #import <ReactCommon/RCTTurboModule.h>
4
5
 
5
6
  // ─── C++ Implementation ───
6
7
 
@@ -71,7 +72,16 @@ jsi::Value RNNSWindow::addWindow(jsi::Runtime &rt, jsi::Object props) {
71
72
  NSString *title = toNSString(p.title);
72
73
  NSString *titleBarStyle = toNSString(p.titleBarStyle);
73
74
  NSString *vibrancy = toNSString(p.vibrancy);
74
- NSString *backgroundColor = toNSString(p.backgroundColor);
75
+ // Read backgroundColor directly from JSI props (it's a processed color:
76
+ // number or object)
77
+ id backgroundColor = nil;
78
+ {
79
+ jsi::Value bgVal = props.getProperty(rt, "backgroundColor");
80
+ if (!bgVal.isNull() && !bgVal.isUndefined()) {
81
+ backgroundColor = TurboModuleConvertUtils::convertJSIValueToObjCObject(
82
+ rt, bgVal, jsInvoker_);
83
+ }
84
+ }
75
85
  BOOL transparent = p.transparent.value_or(false);
76
86
  BOOL hasShadow = p.hasShadow.value_or(true);
77
87
  BOOL resizable = p.resizable.value_or(true);
@@ -177,7 +187,16 @@ jsi::Value RNNSWindow::modifyWindow(jsi::Runtime &rt, jsi::String windowId,
177
187
  NSString *title = toNSString(p.title);
178
188
  NSString *titleBarStyle = toNSString(p.titleBarStyle);
179
189
  NSString *vibrancy = toNSString(p.vibrancy);
180
- NSString *backgroundColor = toNSString(p.backgroundColor);
190
+ // Read backgroundColor directly from JSI props (it's a processed color:
191
+ // number or object)
192
+ id backgroundColor = nil;
193
+ {
194
+ jsi::Value bgVal = props.getProperty(rt, "backgroundColor");
195
+ if (!bgVal.isNull() && !bgVal.isUndefined()) {
196
+ backgroundColor = TurboModuleConvertUtils::convertJSIValueToObjCObject(
197
+ rt, bgVal, jsInvoker_);
198
+ }
199
+ }
181
200
  NSNumber *nTransparent = toNSBool(p.transparent);
182
201
  NSNumber *nHasShadow = toNSBool(p.hasShadow);
183
202
  NSNumber *nResizable = toNSBool(p.resizable);
@@ -28,7 +28,7 @@ class RNNSWindow;
28
28
  title:(NSString *_Nullable)title
29
29
  titleBarStyle:(NSString *_Nullable)titleBarStyle
30
30
  vibrancy:(NSString *_Nullable)vibrancy
31
- backgroundColor:(NSString *_Nullable)backgroundColor
31
+ backgroundColor:(id _Nullable)backgroundColor
32
32
  transparent:(BOOL)transparent
33
33
  hasShadow:(BOOL)hasShadow
34
34
  resizable:(BOOL)resizable
@@ -55,7 +55,7 @@ class RNNSWindow;
55
55
  title:(NSString *_Nullable)title
56
56
  titleBarStyle:(NSString *_Nullable)titleBarStyle
57
57
  vibrancy:(NSString *_Nullable)vibrancy
58
- backgroundColor:(NSString *_Nullable)backgroundColor
58
+ backgroundColor:(id _Nullable)backgroundColor
59
59
  transparent:(NSNumber *_Nullable)transparent
60
60
  hasShadow:(NSNumber *_Nullable)hasShadow
61
61
  resizable:(NSNumber *_Nullable)resizable
@@ -269,7 +269,7 @@
269
269
  title:(NSString *_Nullable)title
270
270
  titleBarStyle:(NSString *_Nullable)titleBarStyle
271
271
  vibrancy:(NSString *_Nullable)vibrancy
272
- backgroundColor:(NSString *_Nullable)backgroundColor
272
+ backgroundColor:(id _Nullable)backgroundColor
273
273
  transparent:(BOOL)transparent
274
274
  hasShadow:(BOOL)hasShadow
275
275
  resizable:(BOOL)resizable
@@ -408,6 +408,18 @@
408
408
  NSView *rootView = [factory viewWithModuleName:componentName
409
409
  initialProperties:initialProps];
410
410
 
411
+ // Make the root view transparent so the native window backgroundColor shows
412
+ // through
413
+ if (transparent) {
414
+ rootView.wantsLayer = YES;
415
+ rootView.layer.backgroundColor = [NSColor clearColor].CGColor;
416
+ rootView.layer.opaque = NO;
417
+ // RCTSurfaceHostingView sets backgroundColor to white by default
418
+ if ([rootView respondsToSelector:@selector(setBackgroundColor:)]) {
419
+ [(id)rootView setBackgroundColor:[NSColor clearColor]];
420
+ }
421
+ }
422
+
411
423
  if (vibrancy && ![vibrancy isEqualToString:@"none"]) {
412
424
  rootView.frame = window.contentView.bounds;
413
425
  rootView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
@@ -452,7 +464,7 @@
452
464
  title:(NSString *_Nullable)title
453
465
  titleBarStyle:(NSString *_Nullable)titleBarStyle
454
466
  vibrancy:(NSString *_Nullable)vibrancy
455
- backgroundColor:(NSString *_Nullable)backgroundColor
467
+ backgroundColor:(id _Nullable)backgroundColor
456
468
  transparent:(NSNumber *_Nullable)transparent
457
469
  hasShadow:(NSNumber *_Nullable)hasShadow
458
470
  resizable:(NSNumber *_Nullable)resizable
@@ -536,6 +548,15 @@
536
548
  // Background color
537
549
  if (transparent) {
538
550
  window.opaque = !transparent.boolValue;
551
+ if (transparent.boolValue) {
552
+ NSView *rootView = window.contentView;
553
+ rootView.wantsLayer = YES;
554
+ rootView.layer.backgroundColor = [NSColor clearColor].CGColor;
555
+ rootView.layer.opaque = NO;
556
+ if ([rootView respondsToSelector:@selector(setBackgroundColor:)]) {
557
+ [(id)rootView setBackgroundColor:[NSColor clearColor]];
558
+ }
559
+ }
539
560
  }
540
561
  if (backgroundColor) {
541
562
  window.backgroundColor = [RCTConvert NSColor:backgroundColor];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nswindow",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Multi-window support for react-native-macos using NSWindow",
5
5
  "author": "Jim Lake <jim@blueskylabs.com>",
6
6
  "homepage": "https://github.com/jim-lake/react-native-nswindow#readme",
@@ -34,7 +34,6 @@ export interface ModifyableWindowProps {
34
34
  | 'fullScreenUI'
35
35
  | 'underWindowBackground'
36
36
  | 'hudWindow';
37
- backgroundColor?: string;
38
37
  transparent?: boolean;
39
38
  hasShadow?: boolean;
40
39
 
package/src/index.ts CHANGED
@@ -1,9 +1,14 @@
1
- export { default } from '../spec/NativeNSWindow';
1
+ import { processColor } from 'react-native';
2
+ import type { ColorValue } from 'react-native';
3
+ import NativeModule from '../spec/NativeNSWindow';
4
+ import type {
5
+ WindowProps as NativeWindowProps,
6
+ ModifyableWindowProps as NativeModifyableWindowProps,
7
+ } from '../spec/NativeNSWindow';
8
+
2
9
  export type {
3
10
  TitleBarStyle,
4
11
  WindowLevel,
5
- WindowProps,
6
- ModifyableWindowProps,
7
12
  WindowState,
8
13
  Rect,
9
14
  Screen,
@@ -12,5 +17,36 @@ export type {
12
17
  WindowMovePayload,
13
18
  WindowResizePayload,
14
19
  WindowOcclusionStatePayload,
15
- Spec,
16
20
  } from '../spec/NativeNSWindow';
21
+
22
+ /**
23
+ * Public-facing props that accept ColorValue (string colors like '#ff0000', 'red', etc.)
24
+ * The module converts these via processColor before passing to native.
25
+ */
26
+ export interface ModifyableWindowProps extends NativeModifyableWindowProps {
27
+ backgroundColor?: ColorValue;
28
+ }
29
+
30
+ export interface WindowProps extends NativeWindowProps {
31
+ backgroundColor?: ColorValue;
32
+ }
33
+
34
+ function processProps(props: Record<string, any>): Record<string, any> {
35
+ const { backgroundColor, ...rest } = props;
36
+ if (backgroundColor) {
37
+ rest.backgroundColor = processColor(backgroundColor);
38
+ }
39
+ return rest;
40
+ }
41
+
42
+ export default {
43
+ ...NativeModule,
44
+
45
+ addWindow(props: WindowProps): Promise<string> {
46
+ return NativeModule.addWindow(processProps(props) as NativeWindowProps);
47
+ },
48
+
49
+ modifyWindow(windowId: string, props: ModifyableWindowProps): Promise<void> {
50
+ return NativeModule.modifyWindow(windowId, processProps(props));
51
+ },
52
+ };