mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-26 07:04:05 +08:00
[ReactNative] Unfork RKRootView
This commit is contained in:
@@ -11,28 +11,29 @@
|
||||
|
||||
#import "RCTRedBox.h"
|
||||
#import "RCTRootView.h"
|
||||
#import "RCTSourceCode.h"
|
||||
|
||||
@interface RCTDevMenu () <UIActionSheetDelegate> {
|
||||
BOOL _liveReload;
|
||||
}
|
||||
|
||||
@property (nonatomic, weak) RCTRootView *view;
|
||||
@property (nonatomic, weak) RCTBridge *bridge;
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTDevMenu
|
||||
|
||||
- (instancetype)initWithRootView:(RCTRootView *)rootView
|
||||
- (instancetype)initWithBridge:(RCTBridge *)bridge
|
||||
{
|
||||
if (self = [super init]) {
|
||||
self.view = rootView;
|
||||
_bridge = bridge;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)show
|
||||
{
|
||||
NSString *debugTitle = self.view.executorClass == nil ? @"Enable Debugging" : @"Disable Debugging";
|
||||
NSString *debugTitle = self.bridge.executorClass == Nil ? @"Enable Debugging" : @"Disable Debugging";
|
||||
NSString *liveReloadTitle = _liveReload ? @"Disable Live Reload" : @"Enable Live Reload";
|
||||
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"React Native: Development"
|
||||
delegate:self
|
||||
@@ -40,16 +41,16 @@
|
||||
destructiveButtonTitle:nil
|
||||
otherButtonTitles:@"Reload", debugTitle, liveReloadTitle, nil];
|
||||
actionSheet.actionSheetStyle = UIBarStyleBlack;
|
||||
[actionSheet showInView:self.view];
|
||||
[actionSheet showInView:[[[[UIApplication sharedApplication] keyWindow] rootViewController] view]];
|
||||
}
|
||||
|
||||
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
|
||||
{
|
||||
if (buttonIndex == 0) {
|
||||
[self.view reload];
|
||||
[self.bridge reload];
|
||||
} else if (buttonIndex == 1) {
|
||||
self.view.executorClass = self.view.executorClass == nil ? NSClassFromString(@"RCTWebSocketExecutor") : nil;
|
||||
[self.view reload];
|
||||
self.bridge.executorClass = self.bridge.executorClass == Nil ? NSClassFromString(@"RCTWebSocketExecutor") : nil;
|
||||
[self.bridge reload];
|
||||
} else if (buttonIndex == 2) {
|
||||
_liveReload = !_liveReload;
|
||||
[self _pollAndReload];
|
||||
@@ -59,7 +60,8 @@
|
||||
- (void)_pollAndReload
|
||||
{
|
||||
if (_liveReload) {
|
||||
NSURL *url = [self.view scriptURL];
|
||||
RCTSourceCode *sourceCodeModule = self.bridge.modules[NSStringFromClass([RCTSourceCode class])];
|
||||
NSURL *url = sourceCodeModule.scriptURL;
|
||||
NSURL *longPollURL = [[NSURL alloc] initWithString:@"/onchange" relativeToURL:url];
|
||||
[self performSelectorInBackground:@selector(_checkForUpdates:) withObject:longPollURL];
|
||||
}
|
||||
@@ -75,7 +77,7 @@
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (_liveReload && response.statusCode == 205) {
|
||||
[[RCTRedBox sharedInstance] dismiss];
|
||||
[self.view reload];
|
||||
[self.bridge reload];
|
||||
}
|
||||
[self _pollAndReload];
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user