Skip to content

Commit 94ad872

Browse files
committed
remove RCTViewController
1 parent f42594f commit 94ad872

8 files changed

Lines changed: 99 additions & 107 deletions

File tree

packages/react-native/Libraries/AppDelegate/RCTDefaultReactNativeFactoryDelegate.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#import "RCTDefaultReactNativeFactoryDelegate.h"
99
#import <ReactCommon/RCTHost.h>
10-
#import <React/RCTViewController.h>
1110
#import "RCTAppSetupUtils.h"
1211
#import "RCTDependencyProvider.h"
1312
#if USE_THIRD_PARTY_JSC != 1
@@ -29,7 +28,7 @@ - (NSURL *_Nullable)sourceURLForBridge:(nonnull RCTBridge *)bridge
2928

3029
- (UIViewController *)createRootViewController
3130
{
32-
return [RCTViewController new];
31+
return [UIViewController new];
3332
}
3433

3534
- (RCTBridge *)createBridgeWithDelegate:(id<RCTBridgeDelegate>)delegate launchOptions:(NSDictionary *)launchOptions

packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTFabricModalHostViewController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#import <React/RCTViewController.h>
8+
#import <UIKit/UIKit.h>
99

1010
@protocol RCTFabricModalHostViewControllerDelegate <NSObject>
1111
- (void)boundsDidChange:(CGRect)newBounds;
1212
@end
1313

14-
@interface RCTFabricModalHostViewController : RCTViewController
14+
@interface RCTFabricModalHostViewController : UIViewController
1515

1616
@property (nonatomic, weak) id<RCTFabricModalHostViewControllerDelegate> delegate;
1717

packages/react-native/React/Views/RCTModalHostViewController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#import <React/RCTViewController.h>
8+
#import <UIKit/UIKit.h>
99

1010
#ifndef RCT_REMOVE_LEGACY_ARCH
1111

1212
__attribute__((deprecated("This API will be removed along with the legacy architecture.")))
13-
@interface RCTModalHostViewController : RCTViewController
13+
@interface RCTModalHostViewController : UIViewController
1414

1515
@property (nonatomic, copy) void (^boundsDidChangeBlock)(CGRect newBounds);
1616

packages/react-native/React/Views/RCTViewController.m

Lines changed: 0 additions & 90 deletions
This file was deleted.

packages/react-native/React/Views/RCTWrapperViewController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#import <React/RCTViewController.h>
8+
#import <UIKit/UIKit.h>
99

1010
@class RCTWrapperViewController;
1111

12-
@interface RCTWrapperViewController : RCTViewController
12+
@interface RCTWrapperViewController : UIViewController
1313

1414
- (instancetype)initWithContentView:(UIView *)contentView NS_DESIGNATED_INITIALIZER;
1515

packages/react-native/React/Views/RCTViewController.h renamed to packages/react-native/React/Views/UIViewController+React.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
1717

1818
@end
1919

20-
@interface UIViewController (RCTViewControllerAppearance)
20+
@interface UIViewController (React)
2121

2222
@property (nonatomic, assign, readonly) BOOL reactViewControllerIsVisible;
2323

@@ -26,17 +26,11 @@ NS_ASSUME_NONNULL_BEGIN
2626

2727
/**
2828
* Call from `viewDidAppear:` / `viewDidDisappear:` in UIViewController subclasses
29-
* that cannot inherit from RCTViewController.
29+
* that want to notify registered React Native appearance listeners.
3030
*/
3131
- (void)reactNotifyViewControllerDidAppear:(BOOL)animated;
3232
- (void)reactNotifyViewControllerDidDisappear:(BOOL)animated;
3333

3434
@end
3535

36-
/**
37-
* UIViewController subclass that forwards appearance events to registered listeners.
38-
*/
39-
@interface RCTViewController : UIViewController
40-
@end
41-
4236
NS_ASSUME_NONNULL_END
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import "UIViewController+React.h"
9+
10+
#import <objc/runtime.h>
11+
12+
@interface RCTViewControllerAppearanceState : NSObject
13+
14+
@property (nonatomic, strong, readonly) NSHashTable<id<RCTViewControllerAppearanceListener>> *listeners;
15+
@property (nonatomic, assign) BOOL visible;
16+
17+
@end
18+
19+
@implementation RCTViewControllerAppearanceState
20+
21+
- (instancetype)init
22+
{
23+
if (self = [super init]) {
24+
_listeners = [NSHashTable weakObjectsHashTable];
25+
}
26+
return self;
27+
}
28+
29+
@end
30+
31+
@implementation UIViewController (React)
32+
33+
- (RCTViewControllerAppearanceState *)reactViewControllerAppearanceState
34+
{
35+
RCTViewControllerAppearanceState *state =
36+
objc_getAssociatedObject(self, @selector(reactViewControllerAppearanceState));
37+
if (!state) {
38+
state = [RCTViewControllerAppearanceState new];
39+
objc_setAssociatedObject(
40+
self, @selector(reactViewControllerAppearanceState), state, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
41+
}
42+
return state;
43+
}
44+
45+
- (BOOL)reactViewControllerIsVisible
46+
{
47+
return [self reactViewControllerAppearanceState].visible;
48+
}
49+
50+
- (void)reactAddViewControllerAppearanceListener:(id<RCTViewControllerAppearanceListener>)listener
51+
{
52+
RCTViewControllerAppearanceState *state = [self reactViewControllerAppearanceState];
53+
[state.listeners addObject:listener];
54+
55+
if (state.visible && [listener respondsToSelector:@selector(reactViewControllerDidAppear:animated:)]) {
56+
[listener reactViewControllerDidAppear:self animated:NO];
57+
}
58+
}
59+
60+
- (void)reactRemoveViewControllerAppearanceListener:(id<RCTViewControllerAppearanceListener>)listener
61+
{
62+
[[self reactViewControllerAppearanceState].listeners removeObject:listener];
63+
}
64+
65+
- (void)reactNotifyViewControllerDidAppear:(BOOL)animated
66+
{
67+
RCTViewControllerAppearanceState *state = [self reactViewControllerAppearanceState];
68+
state.visible = YES;
69+
70+
for (id<RCTViewControllerAppearanceListener> listener in state.listeners.allObjects) {
71+
if ([listener respondsToSelector:@selector(reactViewControllerDidAppear:animated:)]) {
72+
[listener reactViewControllerDidAppear:self animated:animated];
73+
}
74+
}
75+
}
76+
77+
- (void)reactNotifyViewControllerDidDisappear:(BOOL)animated
78+
{
79+
RCTViewControllerAppearanceState *state = [self reactViewControllerAppearanceState];
80+
state.visible = NO;
81+
82+
for (id<RCTViewControllerAppearanceListener> listener in state.listeners.allObjects) {
83+
if ([listener respondsToSelector:@selector(reactViewControllerDidDisappear:animated:)]) {
84+
[listener reactViewControllerDidDisappear:self animated:animated];
85+
}
86+
}
87+
}
88+
89+
@end

packages/react-native/scripts/ios-prebuild/templates/React-umbrella.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@
274274
#import <React/RCTVibration.h>
275275
#import <React/RCTVibrationPlugins.h>
276276
#import <React/RCTView.h>
277-
#import <React/RCTViewController.h>
278277
#import <React/RCTViewManager.h>
279278
#import <React/RCTViewUtils.h>
280279
#import <React/RCTVirtualTextShadowView.h>
@@ -284,6 +283,7 @@
284283
#import <React/RCTWrapperViewController.h>
285284
#import <React/UIView+Private.h>
286285
#import <React/UIView+React.h>
286+
#import <React/UIViewController+React.h>
287287

288288
FOUNDATION_EXPORT double ReactVersionNumber;
289289
FOUNDATION_EXPORT const unsigned char ReactVersionString[];

0 commit comments

Comments
 (0)