Commit Graph

766 Commits

Author SHA1 Message Date
Kevin Gozali 47bfbbb1d3 iOS: introduce RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD() macro to provide the return type of a sync method
Summary:
This provides a way to customize the return type of a sync exported method, instead of just using `id`.

```
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSString *, sync1:(NSString *)x)
{
  return @"hello";
}
```

The return type needs to be a sub type of `id` - so scalars like `double` won't work (the bridge will crash).

Differential Revision: D6068884

fbshipit-source-id: 43a98141f1d0aef335aa0b33a24219f8e574e58b
2017-10-17 06:15:13 -07:00
Marc Horowitz 0a7d5ab753 Add support for FBReactModule (Wilde) to use jsi/hermes with a bcbundle
Reviewed By: danzimm

Differential Revision: D5983822

fbshipit-source-id: ae09c0a33988cb9c3d51e5a18b875698c19a1ec6
2017-10-16 17:07:48 -07:00
James Ide 7733d40237 Move JS-native version check to its own module + unit tests + prefix Obj-C macro w/RCT
Summary:
- The version check that ensures the JS and native versions match is now in its own module for two reasons: it is easier to test and it allows react-native-windows to override just this module to implement its own version check (ex: more advanced checks for RNW-specific code).
- Added unit tests for the version checking to specify its behavior more clearly, including parity between dev and prod to avoid prod-only behavior and mitigate SEVs.
- Prefixed the Obj-C `#define` with `RCT_` to conform with other RN globals.
Closes https://github.com/facebook/react-native/pull/16403

Differential Revision: D6068491

Pulled By: hramos

fbshipit-source-id: 2b255b93982fb9d1b655fc62cb17b126bd5a939a
2017-10-16 14:30:34 -07:00
Alex Dvornikov dd400f842b add "jsBundlesDirectory" method to RCTBridgeDelegate
Differential Revision: D6030185

fbshipit-source-id: 58d6f9d0d412c7ad0f83af9ae4df01c4dc1178bc
2017-10-12 12:33:21 -07:00
Adam Ernst e87904cea5 Redo error handling on iOS
Reviewed By: danzimm

Differential Revision: D5969343

fbshipit-source-id: 376984a6e959349260c54884c0b0b719f4c353d6
2017-10-05 13:31:55 -07:00
Alex Dvornikov afec987e10 Unify sampling profiler and reload logic by leveraging RCTPackagerConnection
Differential Revision: D5951952

fbshipit-source-id: ceea04ebbddb02944717a266a14523be052ab213
2017-10-04 19:17:06 -07:00
Janic Duplessis 1af645b2fd Validate that JS and Native code versions match for RN releases
Summary:
Basic implementation of the proposal in #15271

Note that this should not affect facebook internally since they are not using OSS releases.

Points to consider:
- How strict should the version match be, right now I just match exact versions.
- Wasn't able to use haste for ReactNativeVersion because I was getting duplicate module provider caused by the template file in scripts/versiontemplates. I tried adding the scripts folder to modulePathIgnorePatterns in package.json but that didn't help.
- Redscreen vs. warning, I think warning is useless because if the app crashes you won't have time to see the warning.
- Should the check and native modules be __DEV__ only?

**Test plan**
Tested that it works when version match and that it redscreens when versions don't before getting other errors on Android and iOS.
Closes https://github.com/facebook/react-native/pull/15518

Differential Revision: D5813551

Pulled By: hramos

fbshipit-source-id: 901757e25724b0f22bf39de172b56309d0dd5a95
2017-09-27 18:31:15 -07:00
Jakub Grzmiel d005c8c08a Fix format warnings for clang 5.0
Reviewed By: mzlee

Differential Revision: D5900751

fbshipit-source-id: 4e9aea068aab3d2d882b8fb103a8828e861da97c
2017-09-25 10:30:53 -07:00
Justin Reynolds 3ae45d5cb8 Fix Content-Type header checking of React/RCTJavascriptLoader.mm #15791
Summary:
To fix this issue: https://github.com/facebook/react-native/issues/15791
Closes https://github.com/facebook/react-native/pull/15792

Differential Revision: D5813101

Pulled By: shergin

fbshipit-source-id: fd3eb6f1d9ccdeb5373d1ba2b2df173ff7a8e986
2017-09-19 19:50:07 -07:00
Paco Estevez Garcia 6b733a4fe7 Force local builds to use regular JS bundles
Reviewed By: dcaspi

Differential Revision: D5824552

fbshipit-source-id: a435fc0ad5b43a8bd3c6a873a4147c4d92190f4e
2017-09-18 08:00:33 -07:00
Kellie Medlin e846a9f82f Fix build errors exposed by building against clang 5.0
Reviewed By: rachit-siamwalla

Differential Revision: D5828898

fbshipit-source-id: 23fa587bcd1d1b6c612cc816f1aa7b03da0c187d
2017-09-14 00:35:02 -07:00
Chris Zheng 17126641b1 Removing fallback source URL from JS bridge
Summary:
Remove fallback logic.
It is hard to test whether a bundle is good or bad on device, since it does the fallback, remove the fallback logic now.

Reviewed By: javache

Differential Revision: D5773542

fbshipit-source-id: 8bb4fdad4c5761ccce915f9f1c2577464e8d37d8
2017-09-12 15:54:59 -07:00
Pieter De Baets 7b770556ac Improve RCTCxxBridge invalidation
Reviewed By: fromcelticpark

Differential Revision: D5536063

fbshipit-source-id: b0f19bebea839c7da84890c338ad4d38293bc99c
2017-09-11 04:30:31 -07:00
Alex Dvornikov bd723745c1 Allow Cxx references to be used in native module's method signature
Reviewed By: javache

Differential Revision: D5772182

fbshipit-source-id: 21e2f7b8d14ffdcfc0ba969c9a35315863a19b71
2017-09-07 09:17:04 -07:00
Valentin Shergin c3038d7210 Warn about slow main thread React methods
Summary:
This is revert of revert of https://github.com/facebook/react-native/pull/15542
WITHOUT default RCT_MAIN_THREAD_WATCH_DOG_THRESHOLD value. So, it makes it completly opt-in feature.

When code blocks the UI thread for too long, it's a bad sign because this can prevent the app from remaining responsive. This change helps detect such responsiveness issues by warning when a React method executes on the UI thread longer than some threshold.

Reviewed By: mmmulani

Differential Revision: D5772433

fbshipit-source-id: 24fe4fc0deffe9c091a4bfc4cbd76cb4f34c4091
2017-09-06 16:38:37 -07:00
Marc Horowitz d48f08cad6 Thread the JSI runtime descriptor up into the RCTDevMenu title
Reviewed By: javache

Differential Revision: D5643014

fbshipit-source-id: 977be5729c57c0d01ff67b268031ad6fdbf88a07
2017-09-05 15:02:19 -07:00
James Ide 7d04fbaba2 Change intValue -> integerValue in RCTMultipartStreamReader
Summary:
We assign the value to an NSInteger so we should convert the NSString to an NSInteger instead of an int.

Build the app in Xcode and run it.
Closes https://github.com/facebook/react-native/pull/15806

Differential Revision: D5767118

Pulled By: shergin

fbshipit-source-id: b310511f13f5f4026d595a219d69811801d313c2
2017-09-05 10:02:44 -07:00
Gilad Novik 8a85546ef9 Fix unrecognized selector error
Summary:
Fixes "[NSTaggedPointerString unsignedIntValue]: unrecognized selector" error
Closes https://github.com/facebook/react-native/pull/15755

Differential Revision: D5763628

Pulled By: shergin

fbshipit-source-id: 6e1d1b1ae6bc63e07112b9dddcdf8e6f812a7f51
2017-09-03 23:30:22 -07:00
Mark Smith 998197f444 Clean up some URL path handling
Reviewed By: sahrens

Differential Revision: D5753338

fbshipit-source-id: 0eb1b4ae64ad7170f1b97f398ff11b713c695b12
2017-09-01 13:45:03 -07:00
Alex Dvornikov 77c11e831b RCTManagedPointer fix ups
Reviewed By: javache

Differential Revision: D5727367

fbshipit-source-id: ef6c03e57ee0c40da9411c77f0e8a733945afa07
2017-09-01 08:08:06 -07:00
Jing Chen 6763f7a216 Revert D5724764: [react-native][PR] iOS: Warn about slow main thread React methods
Differential Revision: D5724764

fbshipit-source-id: a2f9c6917aea1d47854a1fd38a51b45c0b624ec2
2017-08-31 12:05:41 -07:00
Ben Nham 259161f872 add files changed count to reload metrics
Reviewed By: alexeylang

Differential Revision: D5694813

fbshipit-source-id: 2e2517e60a7547e261a7c15a3a9138dbb3cb9783
2017-08-31 05:34:48 -07:00
Ben Nham abe7a2a9f1 encapsulate JS source in RCTSource object
Reviewed By: alexeylang

Differential Revision: D5669734

fbshipit-source-id: 60c798afa2115510a17acf9e970e8ba52507724f
2017-08-30 06:29:42 -07:00
Adam Comella 68461492bc iOS: Warn about slow main thread React methods
Summary:
When code blocks the UI thread for too long, it's a bad sign because this can prevent the app from remaining responsive. This change helps detect such responsiveness issues by warning when a React method executes on the UI thread longer than some threshold.

**Test Plan**

Changed AppState's getCurrentAppState method to sleep for 500 ms and verified that a warning was emitted:

```
2017-08-17 19:45:29.479 [warn][tid:main][RCTModuleMethod.mm:527] mainThreadWatchdog: invocation of [RCTAppState getCurrentAppState:error:] took 501ms
```

Adam Comella
Microsoft Corp.
Closes https://github.com/facebook/react-native/pull/15542

Differential Revision: D5724764

Pulled By: shergin

fbshipit-source-id: f1dc4bf17d3657c397720a47fabc7f32bf81b7ac
2017-08-28 22:44:55 -07:00
Paco Estevez Garcia edf60ce640 Fix ENABLE_INSPECTOR ifdef not found during dev
Reviewed By: bnham

Differential Revision: D5680963

fbshipit-source-id: d38c4575387ba58e3819f5aa5c35078ed8ed3e87
2017-08-24 10:46:50 -07:00
Ben Nham 1ce7e4c1e5 add notifications for dev reload
Reviewed By: alexeylang

Differential Revision: D5630472

fbshipit-source-id: 1c44a52fddead361b43551384bbfc73e2d89438f
2017-08-17 17:16:19 -07:00
Paco Estevez Garcia 14e67a379b Fix dev support calls made without an ifdef guard
Reviewed By: danzimm

Differential Revision: D5650480

fbshipit-source-id: d21e76f2bf5bb239a7f21d9d507f054b276568e8
2017-08-17 12:32:06 -07:00
Rafael Oleza 6ad7e8281b Do not send 'hot' parameter when requesting a bundle from iOS
Reviewed By: fromcelticpark

Differential Revision: D5631050

fbshipit-source-id: 1f587f3af68da4d94b5d24afabf7659abb697747
2017-08-16 11:10:32 -07:00
Valentin Shergin a7468a4acf Introducing smart `RCTUnsafeExecuteOnMainQueueOnceSync()` and fixed `RCTScreenScale()`
Summary:
(This diff was decoupled from D4983054 which landing was quite delayed.)

`RCTUnsafeExecuteOnMainQueueOnceSync()` synchronously executes a block once, on main queue.
I found that our old implementation of `RCTScreenScale()` causes deadlock when it is called from main and background thread simultaneously.
After I implemented my own solution I googled this issue and found an article by Ben Alpert with this awesome helper:
https://benalpert.com/2014/04/02/dispatch-once-initialization-on-the-main-thread.html
So, I found it super useful and borrowed it.

Hey spicyj! :)

Reviewed By: fkgozali

Differential Revision: D5632592

fbshipit-source-id: dff43a5780b7404a3cc109c66c131cef4f4df429
2017-08-15 14:25:23 -07:00
Janic Duplessis ef23d2bdcf Show bundle download progress on iOS
Summary:
This shows progress for the download of the JS bundle (different from the packager transform progress that we show already). This is useful especially when loading the JS bundle from a remote source or when developing on device (on simulator + localhost it pretty much just downloads instantly). This will be nice for the expo client since all bundles are loaded over the network and can take several seconds to load.

This depends on https://github.com/facebook/metro-bundler/pull/28 to work but won't crash or anything without it, it just won't show the progress percentage.

![img_05070155d2cc-1](https://user-images.githubusercontent.com/2677334/28293828-2c08d974-6b24-11e7-9334-e106ef3326d9.jpeg)

**Test plan**
Tested that bundle download progress is shown properly in RNTester on both localhost + simulator and on real device with network conditionner to simulate a slow loading bundle.

Tested that it doesn't cause issues if the packager doesn't send the Content-Length header.
Closes https://github.com/facebook/react-native/pull/15066

Differential Revision: D5449073

Pulled By: shergin

fbshipit-source-id: 43a8fb559393bbdc04f77916500e21898695bac5
2017-08-14 11:05:35 -07:00
Paco Estevez Garcia 41504103ce Force the debugger to disconnect before a bundle reload
Reviewed By: bnham

Differential Revision: D5594238

fbshipit-source-id: feff9f179534c8e617f8fa7c8a7b1bc525c07cae
2017-08-14 08:16:52 -07:00
Alex Dvornikov 6783694158 Add support for Cxx objects as arguments to native modules
Reviewed By: fkgozali

Differential Revision: D5589269

fbshipit-source-id: 1bd7004adc397241cabfb1dc59ba1aebad943bf8
2017-08-14 05:22:17 -07:00
Alex Dvornikov 2a6965df90 Refactor memory management of RCTModuleMethod's arguments
Reviewed By: javache

Differential Revision: D5589246

fbshipit-source-id: a4e70268c818f386784b3e20f0fb97a1c89092d3
2017-08-14 05:22:17 -07:00
Dmitry Zakharov cf38b083dd Implement lazy discovery scaffolding for loading NativeModules on demand.
Reviewed By: javache

Differential Revision: D5364734

fbshipit-source-id: 5162f7d41434a3ba38c82fa610e84f865bfacf50
2017-08-11 06:41:33 -07:00
Pieter De Baets 39eb6c5053 Fix podspec test
Summary:
Travis-CI
Closes https://github.com/facebook/react-native/pull/15428

Differential Revision: D5592214

Pulled By: javache

fbshipit-source-id: f006976d7183d845201c001be51d1546c9c31c5a
2017-08-09 07:04:59 -07:00
Pieter De Baets b06bfdd280 Fix crash when converting NSNull values
Reviewed By: fkgozali

Differential Revision: D5583401

fbshipit-source-id: 7adbdaf91c3f7d9a87f44c53ff342c54a04a1e50
2017-08-09 03:35:16 -07:00
Pieter De Baets 0241cb76d1 Improve definition of RCTNilIfNull
Reviewed By: fkgozali

Differential Revision: D5479733

fbshipit-source-id: 460845f79a970dd6614b11de3ce8898ea17ae1dc
2017-08-09 03:35:16 -07:00
Pieter De Baets 220034c4d4 Configure requiresMainQueueSetup for core modules
Reviewed By: fkgozali

Differential Revision: D5528305

fbshipit-source-id: f17cad933685be09784b2246f44baf252bfa5a26
2017-08-07 07:04:36 -07:00
Pieter De Baets d42ccca2e1 Allow native modules to customize the main-thread init behaviour
Summary:
We've simplified a lot of the conditions for eager of the module init so now we can introduce a final switch to allow modules to opt-out (and in the future opt-in if they still require the behaviour).

We now require you to be explicit about the intended behaviour and implement the `+ (BOOL)requiresMainQueueSetup` method on your module. When you return YES from this method, it tells the bridge the module needs to be created on the main thread (and to avoid deadlocks, we do so eagerly during bridge startup). When you return NO, the native module will be initialised when it's first accessed from JS.

The current behaviour is maintained but a warning is emitted until the new API is adopted.

Reviewed By: fkgozali

Differential Revision: D5527788

fbshipit-source-id: 56d38f81e58cf950547b9780e89bfac4667eeaaa
2017-08-07 07:04:36 -07:00
Pieter De Baets f3feca91fc Add deprecation warning to RCTBatchedBridge
Reviewed By: fkgozali

Differential Revision: D5553607

fbshipit-source-id: 94a69264231c4adc1648e34ad64833f042e0d4db
2017-08-04 07:56:14 -07:00
Douglas Lowder 75284d3cd4 Apple TV: Enable long presses on TV remote; dev menu on TV device; example code
Summary:
**Motivation**

Properly support long presses on the Apple TV remote, and also enable dev menu functionality on a real Apple TV device (shaking an Apple TV doesn't work 😄 )

**Test plan**

New example added to `RNTester`.
Closes https://github.com/facebook/react-native/pull/15221

Differential Revision: D5526463

Pulled By: javache

fbshipit-source-id: a61051e86bc82a9561eefc1704bed6b1f2617e05
2017-07-31 04:06:32 -07:00
Kevin Gozali 3149348358 ios: allow application/javascript and text/javascript for packager bundle mime type
Summary: When loading bundle from packager, "application/javascript" and "text/javascript" both refer to JS, so let's allow both for now.

Reviewed By: javache

Differential Revision: D5499446

fbshipit-source-id: f0b42e2fe5dc043a68d2c8df6a9f81e6dd995b57
2017-07-26 11:48:47 -07:00
Philipp von Weitershausen ed903099b4 Add blob implementation with WebSocket integration
Summary:
This is the first PR from a series of PRs grabbou and me will make to add blob support to React Native. The next PR will include blob support for XMLHttpRequest.

I'd like to get this merged with minimal changes to preserve the attribution. My next PR can contain bigger changes.

Blobs are used to transfer binary data between server and client. Currently React Native lacks a way to deal with binary data. The only thing that comes close is uploading files through a URI.

Current workarounds to transfer binary data includes encoding and decoding them to base64 and and transferring them as string, which is not ideal, since it increases the payload size and the whole payload needs to be sent via the bridge every time changes are made.

The PR adds a way to deal with blobs via a new native module. The blob is constructed on the native side and the data never needs to pass through the bridge. Currently the only way to create a blob is to receive a blob from the server via websocket.

The PR is largely a direct port of https://github.com/silklabs/silk/tree/master/react-native-blobs by philikon into RN (with changes to integrate with RN), and attributed as such.

> **Note:** This is a breaking change for all people running iOS without CocoaPods. You will have to manually add `RCTBlob.xcodeproj` to your `Libraries` and then, add it to Build Phases. Just follow the process of manual linking. We'll also need to document this process in the release notes.

Related discussion - https://github.com/facebook/react-native/issues/11103

- `Image` can't show image when `URL.createObjectURL` is used with large images on Android

The websocket integration can be tested via a simple server,

```js
const fs = require('fs');
const http = require('http');

const WebSocketServer = require('ws').Server;

const wss = new WebSocketServer({
  server: http.createServer().listen(7232),
});

wss.on('connection', (ws) => {
  ws.on('message', (d) => {
    console.log(d);
  });

  ws.send(fs.readFileSync('./some-file'));
});
```

Then on the client,

```js
var ws = new WebSocket('ws://localhost:7232');

ws.binaryType = 'blob';

ws.onerror = (error) => {
  console.error(error);
};

ws.onmessage = (e) => {
  console.log(e.data);
  ws.send(e.data);
};
```

cc brentvatne ide
Closes https://github.com/facebook/react-native/pull/11417

Reviewed By: sahrens

Differential Revision: D5188484

Pulled By: javache

fbshipit-source-id: 6afcbc4d19aa7a27b0dc9d52701ba400e7d7e98f
2017-07-26 08:23:20 -07:00
Valentin Shergin 1b9b366cef Removed unused ivar (`_launchOptions`) from `RCTRootView`
Reviewed By: javache

Differential Revision: D5477683

fbshipit-source-id: 05191c98573fe74105d6af2a098f2a8c4479e09c
2017-07-24 09:42:06 -07:00
Pieter De Baets 98258b437c Simplify -[RCTModuleMethod processMethodSignature]
Reviewed By: fromcelticpark

Differential Revision: D5397371

fbshipit-source-id: d341d55fd8bd1a67a0980543f8defedfd12b5dd4
2017-07-24 07:01:53 -07:00
Pieter De Baets cb12080179 Replace exported method registration with statically allocated struct
Reviewed By: fromcelticpark

Differential Revision: D5389383

fbshipit-source-id: 9eb29b254b616574966b43ad24aa880d44589652
2017-07-24 07:01:53 -07:00
Janic Duplessis 3ce36698de Validate the content type of the bundle returned by the packager
Summary:
When using the packager behind something like an http tunnel it is possible something else than JS is returned, in that case throw an error instead of trying to parse it.

This is useful for Expo since the packager runs behind ngrok. This allows to intercept that error and show a more meaningful error message based on the ngrok response.

**Test plan**
Tested by changing the packager to return text/html content type and validate that the error shows up properly.
Also tested that it works when multipart response is disabled.

<img width="354" alt="screen shot 2017-07-19 at 8 01 58 pm" src="https://user-images.githubusercontent.com/2677334/28394905-39e86d52-6cbe-11e7-9059-13a85816a57e.png">
Closes https://github.com/facebook/react-native/pull/15112

Differential Revision: D5459395

Pulled By: shergin

fbshipit-source-id: aaea7ab2e1311ee8dc10feb579adf9b9701d8d4c
2017-07-19 19:10:00 -07:00
Pieter De Baets 980d5140d6 Merge allowOffMainQueueRegistration and requiresMainQueueSetup
Reviewed By: fromcelticpark

Differential Revision: D5398021

fbshipit-source-id: 7e721cce579678f4c82582f5068cf46574afe961
2017-07-17 03:45:30 -07:00
Eli Perkins 78e2030e95 Clean up -[RCTRootView cancelTouches] header docs
Summary:
Just a little typo fixing and wording clean up around some header docs.
Closes https://github.com/facebook/react-native/pull/14947

Differential Revision: D5398609

Pulled By: javache

fbshipit-source-id: 3eb40ef3308130c1d28b2efc7bb64d493e98825b
2017-07-11 11:06:21 -07:00
Pieter De Baets 20224b74a4 Remove deprecated RCTAssert aliases
Reviewed By: fromcelticpark

Differential Revision: D5380783

fbshipit-source-id: 790d7e1bc6d99411ecc471df88f7b1f31680e7a0
2017-07-07 12:21:59 -07:00