Skip to content

Commit ca64282

Browse files
committed
Revert "feat: implement window manager events (#142)" (#147)
This reverts commit 899594b.
1 parent 503a5f3 commit ca64282

File tree

9 files changed

+19
-140
lines changed

9 files changed

+19
-140
lines changed

packages/react-native/Libraries/SwiftExtensions/RCTMainWindow.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ public struct RCTMainWindow: Scene {
2121
var moduleName: String
2222
var initialProps: RCTRootViewRepresentable.InitialPropsType
2323
var onOpenURLCallback: ((URL) -> ())?
24-
let windowId: String = "0"
25-
26-
@Environment(\.scenePhase) private var scenePhase
27-
2824

2925
public init(moduleName: String, initialProps: RCTRootViewRepresentable.InitialPropsType = nil) {
3026
self.moduleName = moduleName
@@ -35,27 +31,13 @@ public struct RCTMainWindow: Scene {
3531
WindowGroup {
3632
RCTRootViewRepresentable(moduleName: moduleName, initialProps: initialProps)
3733
.modifier(WindowHandlingModifier())
38-
.onChange(of: scenePhase, { _, newValue in
39-
postWindowStateNotification(windowId: windowId, state: newValue)
40-
})
4134
.onOpenURL(perform: { url in
4235
onOpenURLCallback?(url)
4336
})
4437
}
4538
}
4639
}
4740

48-
public func postWindowStateNotification(windowId: String, state: SwiftUI.ScenePhase) {
49-
NotificationCenter.default.post(
50-
name: NSNotification.Name(rawValue: "RCTWindowStateDidChange"),
51-
object: nil,
52-
userInfo: [
53-
"windowId": windowId,
54-
"state": "\(state)"
55-
]
56-
)
57-
}
58-
5941
extension RCTMainWindow {
6042
public func onOpenURL(perform action: @escaping (URL) -> ()) -> some Scene {
6143
var scene = self

packages/react-native/Libraries/SwiftExtensions/RCTWindow.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ public struct RCTWindow : Scene {
1313
var id: String
1414
var sceneData: RCTSceneData?
1515
var moduleName: String
16-
@Environment(\.scenePhase) private var scenePhase
17-
1816

1917
public init(id: String, moduleName: String, sceneData: RCTSceneData?) {
2018
self.id = id
@@ -27,9 +25,6 @@ public struct RCTWindow : Scene {
2725
Group {
2826
if let sceneData {
2927
RCTRootViewRepresentable(moduleName: moduleName, initialProps: sceneData.props)
30-
.onChange(of: scenePhase) { _, newValue in
31-
postWindowStateNotification(windowId: id, state: newValue)
32-
}
3328
}
3429
}
3530
.onAppear {
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#import <Foundation/Foundation.h>
22
#import <React/RCTBridgeModule.h>
3-
#import <React/RCTEventEmitter.h>
43

5-
@interface RCTWindowManager : RCTEventEmitter
4+
@interface RCTWindowManager : NSObject <RCTBridgeModule>
65

76
@end

packages/react-native/Libraries/WindowManager/RCTWindowManager.mm

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,14 @@
1010
static NSString *const RCTOpenWindow = @"RCTOpenWindow";
1111
static NSString *const RCTDismissWindow = @"RCTDismissWindow";
1212
static NSString *const RCTUpdateWindow = @"RCTUpdateWindow";
13-
static NSString *const RCTWindowStateDidChangeEvent = @"windowStateDidChange";
1413

15-
static NSString *const RCTWindowStateDidChange = @"RCTWindowStateDidChange";
16-
17-
@interface RCTWindowManager () <NativeWindowManagerSpec> {
18-
BOOL _hasAnyListeners;
19-
}
14+
@interface RCTWindowManager () <NativeWindowManagerSpec>
2015
@end
2116

2217
@implementation RCTWindowManager
2318

2419
RCT_EXPORT_MODULE(WindowManager)
2520

26-
- (void)initialize {
27-
[[NSNotificationCenter defaultCenter] addObserver:self
28-
selector:@selector(handleWindowStateChanges:)
29-
name:RCTWindowStateDidChange
30-
object:nil];
31-
}
32-
33-
- (void)invalidate {
34-
[super invalidate];
35-
[[NSNotificationCenter defaultCenter] removeObserver:self];
36-
}
37-
38-
-(void)startObserving
39-
{
40-
_hasAnyListeners = YES;
41-
}
42-
43-
- (void)stopObserving
44-
{
45-
_hasAnyListeners = NO;
46-
}
47-
4821
RCT_EXPORT_METHOD(openWindow
4922
: (NSString *)windowId userInfo
5023
: (NSDictionary *)userInfo resolve
@@ -95,17 +68,6 @@ - (void)stopObserving
9568
});
9669
}
9770

98-
- (void) handleWindowStateChanges:(NSNotification *)notification {
99-
100-
if (_hasAnyListeners) {
101-
[self sendEventWithName:RCTWindowStateDidChangeEvent body:notification.userInfo];
102-
}
103-
}
104-
105-
- (NSArray<NSString *> *)supportedEvents {
106-
return @[RCTWindowStateDidChangeEvent];
107-
}
108-
10971
- (facebook::react::ModuleConstants<JS::NativeWindowManager::Constants::Builder>)constantsToExport {
11072
return [self getConstants];
11173
}
@@ -125,13 +87,4 @@ - (void) handleWindowStateChanges:(NSNotification *)notification {
12587
return std::make_shared<facebook::react::NativeWindowManagerSpecJSI>(params);
12688
}
12789

128-
+ (BOOL)requiresMainQueueSetup {
129-
return YES;
130-
}
131-
132-
- (dispatch_queue_t)methodQueue
133-
{
134-
return dispatch_get_main_queue();
135-
}
136-
13790
@end

packages/react-native/Libraries/WindowManager/WindowManager.d.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1-
import {NativeEventSubscription} from '../EventEmitter/RCTNativeAppEventEmitter';
2-
3-
type WindowManagerEvents = 'windowStateDidChange';
4-
5-
type WindowState = {
6-
windowId: string;
7-
state: 'active' | 'inactive' | 'background';
8-
};
9-
101
export interface WindowStatic {
112
id: String;
123
open (props?: Object): Promise<void>;
134
update (props: Object): Promise<void>;
145
close (): Promise<void>;
15-
addEventListener (type: WindowManagerEvents, handler: (info: WindowState) => void): NativeEventSubscription;
166
}
177

188
export interface WindowManagerStatic {

packages/react-native/Libraries/WindowManager/WindowManager.js

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,26 @@
11
/**
22
* @format
3-
* @flow strict-local
3+
* @flow strict
44
* @jsdoc
55
*/
66

7-
import NativeEventEmitter from '../EventEmitter/NativeEventEmitter';
8-
import Platform from '../Utilities/Platform';
9-
import {type EventSubscription} from '../vendor/emitter/EventEmitter';
107
import NativeWindowManager from './NativeWindowManager';
118

12-
export type WindowStateValues = 'inactive' | 'background' | 'active';
13-
14-
type WindowManagerEventDefinitions = {
15-
windowStateDidChange: [{state: WindowStateValues, windowId: string}],
16-
};
17-
18-
let emitter: ?NativeEventEmitter<WindowManagerEventDefinitions>;
19-
20-
if (NativeWindowManager != null) {
21-
emitter = new NativeEventEmitter<WindowManagerEventDefinitions>(
22-
Platform.OS !== 'ios' ? null : NativeWindowManager,
23-
);
24-
}
25-
26-
class WindowManager {
27-
static getWindow = function (id: string): Window {
9+
const WindowManager = {
10+
getWindow: function (id: string): Window {
2811
return new Window(id);
29-
};
30-
31-
static addEventListener<K: $Keys<WindowManagerEventDefinitions>>(
32-
type: K,
33-
handler: (...$ElementType<WindowManagerEventDefinitions, K>) => void,
34-
): ?EventSubscription {
35-
return emitter?.addListener(type, handler);
36-
}
12+
},
3713

3814
// $FlowIgnore[unsafe-getters-setters]
39-
static get supportsMultipleScenes(): boolean {
15+
get supportsMultipleScenes(): boolean {
4016
if (NativeWindowManager == null) {
4117
return false;
4218
}
4319

4420
const nativeConstants = NativeWindowManager.getConstants();
4521
return nativeConstants.supportsMultipleScenes || false;
46-
}
47-
}
22+
},
23+
};
4824

4925
class Window {
5026
id: string;

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9764,17 +9764,16 @@ declare export default typeof NativeWindowManager;
97649764
`;
97659765

97669766
exports[`public API should not change unintentionally Libraries/WindowManager/WindowManager.js 1`] = `
9767-
"export type WindowStateValues = \\"inactive\\" | \\"background\\" | \\"active\\";
9768-
type WindowManagerEventDefinitions = {
9769-
windowStateDidChange: [{ state: WindowStateValues, windowId: string }],
9770-
};
9771-
declare class WindowManager {
9772-
static getWindow: $FlowFixMe;
9773-
static addEventListener<K: $Keys<WindowManagerEventDefinitions>>(
9774-
type: K,
9775-
handler: (...$ElementType<WindowManagerEventDefinitions, K>) => void
9776-
): ?EventSubscription;
9777-
static get supportsMultipleScenes(): boolean;
9767+
"declare const WindowManager: {
9768+
getWindow: (id: string) => Window,
9769+
get supportsMultipleScenes(): boolean,
9770+
};
9771+
declare class Window {
9772+
id: string;
9773+
constructor(id: string): void;
9774+
open(props: ?Object): Promise<void>;
9775+
close(): Promise<void>;
9776+
update(props: ?Object): Promise<void>;
97789777
}
97799778
declare module.exports: WindowManager;
97809779
"

packages/react-native/src/private/specs/visionos_modules/NativeWindowManager.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ export interface Spec extends TurboModule {
1919
// $FlowIgnore[unclear-type]
2020
+updateWindow: (windowId: string, userInfo: Object) => Promise<void>;
2121
+closeWindow: (windowId: string) => Promise<void>;
22-
23-
// RCTEventEmitter
24-
+addListener: (eventName: string) => void;
25-
+removeListeners: (count: number) => void;
2622
}
2723

2824
export default (TurboModuleRegistry.get<Spec>('WindowManager'): ?Spec);

packages/rn-tester/js/examples/XR/XRExample.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@ const secondWindow = WindowManager.getWindow('SecondWindow');
1919
const OpenXRSession = () => {
2020
const [isOpen, setIsOpen] = React.useState(false);
2121

22-
React.useEffect(() => {
23-
const listener = WindowManager.addEventListener(
24-
'windowStateDidChange',
25-
data => {
26-
console.log('Window state changed to:', data);
27-
},
28-
);
29-
return () => {
30-
listener?.remove();
31-
};
32-
}, []);
3322
const openXRSession = async () => {
3423
try {
3524
if (!WindowManager.supportsMultipleScenes) {

0 commit comments

Comments
 (0)