mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
74de9526ab
Summary: Recently, I've introduced `RCTReactNativeFactory` in this PR: https://github.com/facebook/react-native/issues/46298, which is a good successor for `RCTAppDelegate`. ### Why? `RCTAppDelegate` introduced strong coupling between React Native and AppDelegate pattern. From iOS 13+ there is a newer equivalent (Scene Delegate) which is not possible to achieve with current architecture. The proposed solution involves migration to a `RCTReactNativeFactory` a class that encapsulates initialization logic of React Native. This migration will make brownfield initialization easier by making it more flexible and simpler to integrate into already established apps. ### Deprecation plan The plan I've discussed with cipolleschi involves: - Deprecation of `RCTAppDelegate` in 0.79 (current main) - Migration off `RCTAppDelegate` to SceneDelegate + `RCTReactNativeFactory` in 0.80 ## Changelog: [IOS] [DEPRECATED] - deprecate RCTAppDelegate Pull Request resolved: https://github.com/facebook/react-native/pull/49078 Test Plan: Not needed Reviewed By: cortinico Differential Revision: D69061022 Pulled By: cipolleschi fbshipit-source-id: b02a0ff3f26be9320da749f38c9cf083804f9f30
90 lines
2.3 KiB
Plaintext
90 lines
2.3 KiB
Plaintext
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "UpdatePropertiesExampleView.h"
|
|
|
|
#import <React/RCTRootView.h>
|
|
#import <React/RCTViewManager.h>
|
|
|
|
#import "AppDelegate.h"
|
|
|
|
@interface UpdatePropertiesExampleViewManager : RCTViewManager
|
|
|
|
@end
|
|
|
|
@implementation UpdatePropertiesExampleViewManager
|
|
|
|
RCT_EXPORT_MODULE();
|
|
|
|
- (UIView *)view
|
|
{
|
|
return [UpdatePropertiesExampleView new];
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation UpdatePropertiesExampleView {
|
|
RCTRootView *_rootView;
|
|
UIButton *_button;
|
|
BOOL _beige;
|
|
}
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
_beige = YES;
|
|
|
|
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
|
|
|
|
_rootView =
|
|
(RCTRootView *)[appDelegate.reactNativeFactory.rootViewFactory viewWithModuleName:@"SetPropertiesExampleApp"
|
|
initialProperties:@{@"color" : @"beige"}];
|
|
|
|
_button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
|
|
[_button setTitle:@"Native Button" forState:UIControlStateNormal];
|
|
[_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
[_button setBackgroundColor:[UIColor grayColor]];
|
|
|
|
[_button addTarget:self action:@selector(changeColor) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
[self addSubview:_button];
|
|
[self addSubview:_rootView];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)layoutSubviews
|
|
{
|
|
float spaceHeight = 20;
|
|
float buttonHeight = 40;
|
|
float rootViewWidth = self.bounds.size.width;
|
|
float rootViewHeight = self.bounds.size.height - spaceHeight - buttonHeight;
|
|
|
|
[_rootView setFrame:CGRectMake(0, 0, rootViewWidth, rootViewHeight)];
|
|
[_button setFrame:CGRectMake(0, rootViewHeight + spaceHeight, rootViewWidth, buttonHeight)];
|
|
}
|
|
|
|
- (void)changeColor
|
|
{
|
|
_beige = !_beige;
|
|
|
|
NSMutableDictionary *newProperties = [_rootView.appProperties mutableCopy];
|
|
newProperties[@"color"] = _beige ? @"beige" : @"purple";
|
|
|
|
[_rootView setAppProperties:newProperties];
|
|
}
|
|
|
|
- (NSArray<UIView<RCTComponent> *> *)reactSubviews
|
|
{
|
|
// this is to avoid unregistering our RCTRootView when the component is removed from RN hierarchy
|
|
(void)[super reactSubviews];
|
|
return @[];
|
|
}
|
|
|
|
@end
|