Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Hyper-V Android Emulator Setup Instructions. Closes #3234 #5117

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Examples/UIExplorer/UIExplorer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; };
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
13B6C1A31C34225900D3FAF5 /* RCTURLUtilsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B6C1A21C34225900D3FAF5 /* RCTURLUtilsTests.m */; };
13DB03481B5D2ED500C27245 /* RCTJSONTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 13DB03471B5D2ED500C27245 /* RCTJSONTests.m */; };
13DF61B61B67A45000EDB188 /* RCTMethodArgumentTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 13DF61B51B67A45000EDB188 /* RCTMethodArgumentTests.m */; };
143BC5A11B21E45C00462512 /* UIExplorerSnapshotTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 143BC5A01B21E45C00462512 /* UIExplorerSnapshotTests.m */; };
Expand Down Expand Up @@ -198,6 +199,7 @@
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = UIExplorer/Images.xcassets; sourceTree = "<group>"; };
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = UIExplorer/Info.plist; sourceTree = "<group>"; };
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = UIExplorer/main.m; sourceTree = "<group>"; };
13B6C1A21C34225900D3FAF5 /* RCTURLUtilsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTURLUtilsTests.m; sourceTree = "<group>"; };
13CC9D481AEED2B90020D1C2 /* RCTSettings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTSettings.xcodeproj; path = ../../Libraries/Settings/RCTSettings.xcodeproj; sourceTree = "<group>"; };
13DB03471B5D2ED500C27245 /* RCTJSONTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTJSONTests.m; sourceTree = "<group>"; };
13DF61B51B67A45000EDB188 /* RCTMethodArgumentTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTMethodArgumentTests.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -406,6 +408,7 @@
143BC57C1B21E18100462512 /* UIExplorerUnitTests */ = {
isa = PBXGroup;
children = (
13B6C1A21C34225900D3FAF5 /* RCTURLUtilsTests.m */,
1497CFA41B21F5E400C1F8F2 /* RCTAllocationTests.m */,
1497CFA51B21F5E400C1F8F2 /* RCTBridgeTests.m */,
1497CFA61B21F5E400C1F8F2 /* RCTJSCExecutorTests.m */,
Expand Down Expand Up @@ -886,6 +889,7 @@
1497CFAC1B21F5E400C1F8F2 /* RCTAllocationTests.m in Sources */,
13DF61B61B67A45000EDB188 /* RCTMethodArgumentTests.m in Sources */,
138D6A181B53CD440074A87E /* RCTShadowViewTests.m in Sources */,
13B6C1A31C34225900D3FAF5 /* RCTURLUtilsTests.m in Sources */,
8385CF041B87479200C6273E /* RCTImageLoaderHelpers.m in Sources */,
8385CEF51B873B5C00C6273E /* RCTImageLoaderTests.m in Sources */,
);
Expand Down
75 changes: 75 additions & 0 deletions Examples/UIExplorer/UIExplorerUnitTests/RCTURLUtilsTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* The examples provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#import <XCTest/XCTest.h>
#import "RCTUtils.h"

@interface RCTURLUtilsTests : XCTestCase

@end

@implementation RCTURLUtilsTests

- (void)testGetQueryParam
{
NSURL *URL = [NSURL URLWithString:@"http://example.com?foo=bar&bar=foo"];
NSString *foo = RCTGetURLQueryParam(URL, @"foo");
NSString *bar = RCTGetURLQueryParam(URL, @"bar");
XCTAssertEqualObjects(foo, @"bar");
XCTAssertEqualObjects(bar, @"foo");
}

- (void)testQueryParamNotFound
{
NSURL *URL = [NSURL URLWithString:@"http://example.com?foo=bar"];
NSString *bar = RCTGetURLQueryParam(URL, @"bar");
XCTAssertNil(bar);
}

- (void)testDuplicateParamTakesLatter
{
NSURL *URL = [NSURL URLWithString:@"http://example.com?foo=bar&foo=foo"];
NSString *foo = RCTGetURLQueryParam(URL, @"foo");
XCTAssertEqualObjects(foo, @"foo");
}

- (void)testNilURLGetQueryParam
{
NSURL *URL = nil;
NSString *foo = RCTGetURLQueryParam(URL, @"foo");
XCTAssertNil(foo);
}

- (void)testReplaceParam
{
NSURL *URL = [NSURL URLWithString:@"http://example.com?foo=bar&bar=foo"];
NSURL *result = RCTURLByReplacingQueryParam(URL, @"foo", @"foo");
XCTAssertEqualObjects(result.absoluteString, @"http://example.com?foo=foo&bar=foo");
}

- (void)testAppendParam
{
NSURL *URL = [NSURL URLWithString:@"http://example.com?bar=foo"];
NSURL *result = RCTURLByReplacingQueryParam(URL, @"foo", @"bar");
XCTAssertEqualObjects(result.absoluteString, @"http://example.com?bar=foo&foo=bar");
}

- (void)testNilURLAppendQueryParam
{
NSURL *URL = nil;
NSURL *result = RCTURLByReplacingQueryParam(URL, @"foo", @"bar");
XCTAssertNil(result);
}

@end
23 changes: 18 additions & 5 deletions Libraries/Utilities/HMRClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,32 @@ const HMRClient = {
invariant(platform, 'Missing required parameter `platform`');
invariant(bundleEntry, 'Missing required paramenter `bundleEntry`');

// TODO(martinb) receive host and port as parameters
const host = 'localhost';
const port = '8081';

// need to require WebSocket inside of `enable` function because the
// this module is defined as a `polyfillGlobal`.
// See `InitializeJavascriptAppEngine.js`
const WebSocket = require('WebSocket');

// TODO(martinb): parametrize the url and receive entryFile to minimize
// the number of updates we want to receive from the server.
const activeWS = new WebSocket(
'ws://localhost:8081/hot?platform=' + platform + '&bundleEntry=' +
bundleEntry.replace('.bundle', '.js')
`ws://${host}:${port}/hot?platform=${platform}&` +
`bundleEntry=${bundleEntry.replace('.bundle', '.js')}`
);
activeWS.onerror = (e) => {
console.error('[Hot Module Replacement] Unexpected error', e);
throw new Error(
`Hot loading isn't working because it cannot connect to the development server.

Ensure the following:
- Node server is running and available on the same network
- run 'npm start' from react-native root
- Node server URL is correctly set in AppDelegate

URL: ${host}:${port}

Error: ${e.message}`
);
};
activeWS.onmessage = (m) => {
eval(m.data); // eslint-disable-line no-eval
Expand Down
39 changes: 35 additions & 4 deletions React/Base/RCTBatchedBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
typedef NS_ENUM(NSUInteger, RCTBridgeFields) {
RCTBridgeFieldRequestModuleIDs = 0,
RCTBridgeFieldMethodIDs,
RCTBridgeFieldParamss,
RCTBridgeFieldParams,
RCTBridgeFieldCallID,
};

RCT_EXTERN NSArray<Class> *RCTGetModuleClasses(void);
Expand Down Expand Up @@ -65,6 +66,9 @@ @implementation RCTBatchedBridge
NSUInteger _asyncInitializedModules;
}

@synthesize flowID = _flowID;
@synthesize flowIDMap = _flowIDMap;

- (instancetype)initWithParentBridge:(RCTBridge *)bridge
{
RCTAssertMainThread();
Expand Down Expand Up @@ -440,6 +444,16 @@ - (void)executeSourceCode:(NSData *)sourceCode
object:_parentBridge userInfo:@{@"bridge": self}];
});
}];

#if RCT_DEV

if (RCTGetURLQueryParam(self.bundleURL, @"hot")) {
NSString *path = [self.bundleURL.path substringFromIndex:1]; // strip initial slash
[self enqueueJSCall:@"HMRClient.enable" args:@[@"ios", path]];
}

#endif

}

- (void)didFinishLoading
Expand Down Expand Up @@ -581,6 +595,9 @@ - (void)invalidate
_modulesByName_DEPRECATED = nil;
_frameUpdateObservers = nil;

if (_flowIDMap != NULL) {
CFRelease(_flowIDMap);
}
}];
});
}
Expand Down Expand Up @@ -783,15 +800,22 @@ - (void)handleBuffer:(id)buffer batchEnded:(BOOL)batchEnded
- (void)handleBuffer:(NSArray *)buffer
{
NSArray *requestsArray = [RCTConvert NSArray:buffer];
if (RCT_DEBUG && requestsArray.count <= RCTBridgeFieldParamss) {

if (RCT_DEBUG && requestsArray.count <= RCTBridgeFieldParams) {
RCTLogError(@"Buffer should contain at least %tu sub-arrays. Only found %tu",
RCTBridgeFieldParamss + 1, requestsArray.count);
RCTBridgeFieldParams + 1, requestsArray.count);
return;
}

NSArray<NSNumber *> *moduleIDs = [RCTConvert NSNumberArray:requestsArray[RCTBridgeFieldRequestModuleIDs]];
NSArray<NSNumber *> *methodIDs = [RCTConvert NSNumberArray:requestsArray[RCTBridgeFieldMethodIDs]];
NSArray<NSArray *> *paramsArrays = [RCTConvert NSArrayArray:requestsArray[RCTBridgeFieldParamss]];
NSArray<NSArray *> *paramsArrays = [RCTConvert NSArrayArray:requestsArray[RCTBridgeFieldParams]];

int64_t callID = -1;

if (requestsArray.count > 3) {
callID = [requestsArray[RCTBridgeFieldCallID] longLongValue];
}

if (RCT_DEBUG && (moduleIDs.count != methodIDs.count || moduleIDs.count != paramsArrays.count)) {
RCTLogError(@"Invalid data message - all must be length: %zd", moduleIDs.count);
Expand Down Expand Up @@ -825,6 +849,11 @@ - (void)handleBuffer:(NSArray *)buffer
@autoreleasepool {
for (NSNumber *indexObj in calls) {
NSUInteger index = indexObj.unsignedIntegerValue;
if (callID != -1) {
int64_t newFlowID = (int64_t)CFDictionaryGetValue(_flowIDMap, (const void *)(_flowID + index));
_RCTProfileEndFlowEvent(@(newFlowID));
CFDictionaryRemoveValue(_flowIDMap, (const void *)(_flowID + index));
}
[self _handleRequestNumber:index
moduleID:[moduleIDs[index] integerValue]
methodID:[methodIDs[index] integerValue]
Expand All @@ -843,6 +872,8 @@ - (void)handleBuffer:(NSArray *)buffer
dispatch_async(queue, block);
}
}

_flowID = callID;
}

- (void)partialBatchDidFlush
Expand Down
9 changes: 9 additions & 0 deletions React/Base/RCTBridge+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

@interface RCTBridge ()

// Used for the profiler flow events between JS and native
@property (nonatomic, assign) int64_t flowID;
@property (nonatomic, assign) CFMutableDictionaryRef flowIDMap;

+ (instancetype)currentBridge;
+ (void)setCurrentBridge:(RCTBridge *)bridge;

Expand Down Expand Up @@ -41,6 +45,11 @@
*/
@property (nonatomic, copy, readonly) RCTBridgeModuleProviderBlock moduleProvider;

/**
* Used by RCTDevMenu to override the `hot` param of the current bundleURL.
*/
@property (nonatomic, strong, readwrite) NSURL *bundleURL;

@end

@interface RCTBridge (RCTBatchedBridge)
Expand Down
6 changes: 3 additions & 3 deletions React/Base/RCTBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ RCT_EXTERN BOOL RCTBridgeModuleClassIsRegistered(Class);
/**
* URL of the script that was loaded into the bridge.
*/
@property (nonatomic, strong) NSURL *bundleURL;
@property (nonatomic, strong, readonly) NSURL *bundleURL;

/**
* The class of the executor currently being used *or* to be used after the next
* reload.
* The class of the executor currently being used. Changes to this value will
* take effect after the bridge is reloaded.
*/
@property (nonatomic, strong) Class executorClass;

Expand Down
12 changes: 9 additions & 3 deletions React/Base/RCTBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#import "RCTLog.h"
#import "RCTPerformanceLogger.h"
#import "RCTUtils.h"
#import "RCTBundleURLProcessor.h"

NSString *const RCTReloadNotification = @"RCTReloadNotification";
NSString *const RCTJavaScriptWillStartLoadingNotification = @"RCTJavaScriptWillStartLoadingNotification";
Expand Down Expand Up @@ -88,6 +87,9 @@ BOOL RCTBridgeModuleClassIsRegistered(Class cls)
}

@implementation RCTBridge
{
NSURL *_delegateBundleURL;
}

dispatch_queue_t RCTJSThread;

Expand Down Expand Up @@ -257,8 +259,12 @@ - (void)setUp
{
RCTAssertMainThread();

_bundleURL = [self.delegate sourceURLForBridge:self] ?: _bundleURL;
_bundleURL = [[RCTBundleURLProcessor sharedProcessor] process: _bundleURL];
// Only update bundleURL from delegate if delegate bundleURL has changed
NSURL *previousDelegateURL = _delegateBundleURL;
_delegateBundleURL = [self.delegate sourceURLForBridge:self];
if (_delegateBundleURL && ![_delegateBundleURL isEqual:previousDelegateURL]) {
_bundleURL = _delegateBundleURL;
}

// Sanitize the bundle URL
_bundleURL = [RCTConvert NSURL:_bundleURL.absoluteString];
Expand Down
6 changes: 3 additions & 3 deletions React/Base/RCTBridgeDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ typedef void (^RCTSourceLoadBlock)(NSError *error, NSData *source);
withBlock:(RCTSourceLoadBlock)loadCallback;

/**
* Indicates wheather Hot Loading is supported or not.
* Note this method will get removed soon, once we support Hot Loading on OSS.
* Indicates whether Hot Loading is supported or not.
* Note: this method will be removed soon, once Hot Loading is supported on OSS.
*/
- (BOOL)isHotLoadingEnabled;
- (BOOL)bridgeSupportsHotLoading:(RCTBridge *)bridge;

@end
18 changes: 0 additions & 18 deletions React/Base/RCTBundleURLProcessor.h

This file was deleted.

Loading