-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first phase of synchronizing earlgrey with react native
two mechanisms: bridge sync + uimanager dispatch queue sync
- Loading branch information
talkol
committed
Aug 15, 2016
1 parent
78012d1
commit ef0ad93
Showing
9 changed files
with
383 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
GREYDispatchQueueIdlingResource: | ||
+ (instancetype)resourceWithDispatchQueue:(dispatch_queue_t)queue name:(NSString *)name; | ||
we need dispatch_queue_t | ||
+ (instancetype)resourceWithNSOperationQueue:(NSOperationQueue *)queue name:(NSString *)name; | ||
we need NSOperationQueue | ||
|
||
enqueueJSCall | ||
|
||
- (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block | ||
{ | ||
if ([NSThread currentThread] != _javaScriptThread) { | ||
[self performSelector:@selector(executeBlockOnJavaScriptQueue:) | ||
onThread:_javaScriptThread withObject:block waitUntilDone:NO]; | ||
} else { | ||
block(); | ||
} | ||
} | ||
|
||
1. CFRunLoopIsWaiting ?? - the JS thread is a thread, it isn't a GCD queue so it's hard | ||
This function is useful only to test the state of another thread’s run loop. When called with the current thread’s run loop, this function always returns false. | ||
#import "Additions/NSRunLoop+GREYAdditions.h" | ||
|
||
http://tadeuzagallo.com/blog/react-native-bridge/ | ||
|
||
|
||
RCTFrameUpdateObserver - a react native module can ask to receive a callback before every frame is drawn to screen (using CADisplayLink) | ||
|
||
2. RCTTiming.m | ||
maybe listen in on all timers in the system and add EarlGrey monitors to them | ||
|
||
RCT_PROFILE_BEGIN_EVENT | ||
RCT_PROFILE_END_EVENT | ||
we can maybe enable profiling and listen on RCTProfileGetQueue() | ||
|
||
flushedQueue (js) | ||
|
||
dispatch_queue_create("com.facebook.react.RCTBridgeQueue", DISPATCH_QUEUE_CONCURRENT); | ||
|
||
_pendingCalls | ||
|
||
enqueueJSCall | ||
|
||
char *const RCTUIManagerQueueName = "com.facebook.react.ShadowQueue"; | ||
RCTGetUIManagerQueue | ||
_pendingUIBlocks | ||
|
||
if (![_bridge isBatchActive]) | ||
|
||
MessageQueue.js | ||
flushedQueue() | ||
Systrace.counterEvent('pending_js_to_native_queue', this._queue[0].length); | ||
|
||
RCTJSThread | ||
|
||
[self executeBlockOnJavaScriptQueue:^{ | ||
BOOL enabled = [notification.name isEqualToString:RCTProfileDidStartProfiling]; | ||
[_bridge enqueueJSCall:@"Systrace.setEnabled" args:@[enabled ? @YES : @NO]]; | ||
}]; | ||
|
||
JSEvaluateScript | ||
|
||
addSynchronousHookWithName | ||
// can make a JS function that when executes, runs native code synchronously and gets a return value from native | ||
|
||
InteractionManager.runAfterInteractions | ||
* - requestAnimationFrame(): for code that animates a view over time. | ||
* - setImmediate/setTimeout(): run code later, note this may delay animations. | ||
* - runAfterInteractions(): run code later, without delaying active animations. | ||
|
||
BatchedBridge.js getEventLoopRunningTime() - see how much time passed after last flush | ||
|
||
JSTimersExecution.js | ||
JSTimersExecution.Type.requestIdleCallback | ||
callImmediatesPass() return JSTimersExecution.immediates.length > 0 | ||
|
||
requestAnimationFrame - is a polyfill from the browser that you might be familiar with. It accepts a function as its only argument and calls that function before the next repaint | ||
|
||
ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactIdleDetectionUtil.java | ||
* Waits for both the UI thread and bridge to be idle. It determines this by waiting for the | ||
* bridge to become idle, then waiting for the UI thread to become idle, then checking if the | ||
* bridge is idle again (if the bridge was idle before and is still idle after running the UI | ||
* thread to idle, then there are no more events to process in either place). | ||
|
||
NSRunLoop *targetRunLoop = [_javaScriptExecutor isKindOfClass:[RCTJSCExecutor class]] ? [NSRunLoop currentRunLoop] : [NSRunLoop mainRunLoop]; | ||
[_displayLink addToRunLoop:targetRunLoop]; | ||
|
||
GREYUIWebViewIdlingResource.m | ||
* this is an implementation by EarlGrey that waits on a webview until it becomes idle | ||
* we can do a very similar concept |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
detox/ios/Detox.xcodeproj/project.xcworkspace/contents.xcworkspacedata
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// ReactNativeBridgeIdlingResource.h | ||
// Detox | ||
// | ||
// Created by Tal Kol on 8/15/16. | ||
// Copyright © 2016 Wix. All rights reserved. | ||
// | ||
|
||
#import <EarlGrey/GREYIdlingResource.h> | ||
#import <Foundation/Foundation.h> | ||
|
||
@interface ReactNativeBridgeIdlingResource : NSObject<GREYIdlingResource> | ||
|
||
+ (instancetype)idlingResourceForBridge:(id)bridge name:(NSString *)name; | ||
+ (void)deregister:(ReactNativeBridgeIdlingResource*)instance; | ||
- (instancetype)init NS_UNAVAILABLE; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// | ||
// ReactNativeBridgeIdlingResource.m | ||
// Detox | ||
// | ||
// Created by Tal Kol on 8/15/16. | ||
// Copyright © 2016 Wix. All rights reserved. | ||
// | ||
|
||
#import "ReactNativeHeaders.h" | ||
#import "ReactNativeBridgeIdlingResource.h" | ||
#import "Common/GREYDefines.h" | ||
#import "Common/GREYPrivate.h" | ||
|
||
typedef enum { | ||
kWaiting, | ||
kBusy, | ||
kIdle | ||
} IdlingCheckState; | ||
|
||
@implementation ReactNativeBridgeIdlingResource | ||
{ | ||
NSString *_name; | ||
id<RN_RCTBridge> _bridge; | ||
IdlingCheckState _state; | ||
int _consecutiveIdles; | ||
} | ||
|
||
+ (instancetype)idlingResourceForBridge:(id)bridge name:(NSString *)name | ||
{ | ||
if (bridge == nil) | ||
{ | ||
Class<RN_RCTBridge> RCTBridge = NSClassFromString(@"RCTBridge"); | ||
if (RCTBridge == nil) return nil; | ||
bridge = [RCTBridge currentBridge]; | ||
} | ||
|
||
if (bridge == nil) return nil; | ||
ReactNativeBridgeIdlingResource *res = [[ReactNativeBridgeIdlingResource alloc] initWithBridge:bridge name:name]; | ||
[[GREYUIThreadExecutor sharedInstance] registerIdlingResource:res]; | ||
return res; | ||
} | ||
|
||
+ (void)deregister:(ReactNativeBridgeIdlingResource*)instance | ||
{ | ||
[[GREYUIThreadExecutor sharedInstance] deregisterIdlingResource:instance]; | ||
} | ||
|
||
- (instancetype)initWithBridge:(id<RN_RCTBridge>)bridge name:(NSString *)name | ||
{ | ||
self = [super init]; | ||
if (self) | ||
{ | ||
_name = [name copy]; | ||
_bridge = bridge; | ||
_state = kBusy; | ||
_consecutiveIdles = 0; | ||
} | ||
return self; | ||
} | ||
|
||
#pragma mark - GREYIdlingResource | ||
|
||
- (NSString *)idlingResourceName { | ||
return _name; | ||
} | ||
|
||
- (NSString *)idlingResourceDescription { | ||
return _name; | ||
} | ||
|
||
- (BOOL)isIdleNow | ||
{ | ||
if (_bridge == nil) return NO; | ||
if (![_bridge isValid] || [_bridge isLoading]) return NO; | ||
id<RN_RCTJavaScriptExecutor> executor = [_bridge valueForKey:@"javaScriptExecutor"]; | ||
if (executor == nil) return NO; | ||
|
||
if (_state == kIdle) | ||
{ | ||
_consecutiveIdles++; | ||
} | ||
else | ||
{ | ||
_consecutiveIdles = 0; | ||
} | ||
if (_state != kWaiting) | ||
{ | ||
_state = kWaiting; | ||
[executor executeBlockOnJavaScriptQueue:^{ | ||
[executor flushedQueue:^(id json, NSError *error) { | ||
if (error == nil && json != nil) _state = kBusy; | ||
else _state = kIdle; | ||
}]; | ||
}]; | ||
} | ||
BOOL res = NO; | ||
if (_consecutiveIdles > 2) res = YES; | ||
// NSLog(@"ReactNativeBridgeIdlingResource: idle=%d (%d)", res, _consecutiveIdles); | ||
return res; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// ReactNativeHeaders.h | ||
// Detox | ||
// | ||
// Created by Tal Kol on 8/15/16. | ||
// Copyright © 2016 Wix. All rights reserved. | ||
// | ||
|
||
#ifndef ReactNativeHeaders_h | ||
#define ReactNativeHeaders_h | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
// we don't want detox to have a direct dependency on ReactNative | ||
|
||
typedef void (^RN_RCTJavaScriptCallback)(id json, NSError *error); | ||
|
||
@protocol RN_RCTUIManager | ||
- (dispatch_queue_t)methodQueue; | ||
@end | ||
|
||
@protocol RN_RCTBridge | ||
+ (id)currentBridge; | ||
- (id<RN_RCTUIManager>) uiManager; | ||
- (id)valueForKey:(NSString*)key; | ||
@property (nonatomic, readonly, getter=isLoading) BOOL loading; | ||
@property (nonatomic, readonly, getter=isValid) BOOL valid; | ||
@end | ||
|
||
@protocol RN_RCTJavaScriptExecutor | ||
- (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block; | ||
- (void)flushedQueue:(RN_RCTJavaScriptCallback)onComplete; | ||
@end | ||
|
||
#endif /* ReactNativeHeaders_h */ |
Oops, something went wrong.