Граф коммитов

48 Коммитов

Автор SHA1 Сообщение Дата
Lulu Wu de477a0df6 Register RCTEventEmitter as callable module for Venice
Summary:
## Context
Trying to fix this js error
```
com.facebook.errorreporting.lacrima.common.exception.LacrimaJavascriptException: Error: Module RCTEventEmitter has not been registered as callable. Did you forget to call `RN$registerCallableModule`?, js build: UNKNOWN
```
https://fburl.com/logview/fvc33d48

Changelog:
[General][Changed] - Register RCTEventEmitter as callable module for Venice

Reviewed By: PeteTheHeat

Differential Revision: D27969226

fbshipit-source-id: 8e807ee5b2ef447b0bb49fa2107352d89584c181
2021-04-23 13:32:05 -07:00
Rubén Norte 158e17f6a0 Fix incorrect warning on NativeEventEmitter when nativeModule is null
Summary: Changelog: [Internal]

Reviewed By: ShikaSD

Differential Revision: D27881851

fbshipit-source-id: 3b1cba618a86aff1e1c7ffbc0ea5d7047713d30a
2021-04-20 08:45:42 -07:00
Rubén Norte 114be1d217 Check existence of native methods before calling them in NativeEventEmitter
Summary:
Check the existence of `addListener` and `removeListeners` in the native module passed to `NativeEventEmitter` to determine if it can be used.

Changelog: [General][Changed] Show warning when native module without `addListener` or `removeListeners` is passed to `NativeEventEmitter`

Reviewed By: yungsters

Differential Revision: D27851425

fbshipit-source-id: c0ad3ba65a9239f5bf84548dab36e8dfbc51058a
2021-04-19 13:14:38 -07:00
Rubén Norte f5502fbda9 Use native module passed to NativeEventEmitter on Android
Summary:
## Context

In native modules implementing an event emitter, we can wait for JS to subscribe to an event before making the subscription to the right native API in the native module. This is only supported on iOS at the moment and we want to support it on Android too, so we can manage resources more efficiently and avoid custom code to do this on Android, like this:

https://www.internalfb.com/intern/diffusion/FBS/browse/master/xplat/js/RKJSModules/public/Dating/Profile/ProfileView/ProfileGemstoneProfileView.js?commit=165ad219e6bf&lines=302-304

The way this works now is by creating instances of `NativeEventEmitter`, where we pass a reference to the native module that needs to be notified when there are new subscriptions. We have explicit code to ignore this native modules in all platforms except for iOS:
https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/xplat/js/react-native-github/Libraries/EventEmitter/NativeEventEmitter.js?commit=5a1e671453465e844dd851c458cb2467a2db5d03&lines=44-52

## Changes

This removes the check for iOS from `NativeEventEmitter` so we also try to use the native module to notify subscriptions on Android.

We have migrated all existing code passing a native module to `NativeEventEmtiter` to only pass it on iOS, so we don't change this behavior in existing code.

Any other existing code using this API is most likely fine too. It didn't work before so the expectation is that the native module wouldn't be implemented on Android anyway.

Changelog: [Android][Changed] - Modified `NativeEventEmitter` to also use the passed native module to report subscriptions on Android

Reviewed By: yungsters

Differential Revision: D27500994

fbshipit-source-id: ef82da04020fb08cd0ea4f1cfffd1da6453ab0b9
2021-04-12 06:27:20 -07:00
Daniel Sainati 05418f8fcc codemod objects to interfaces where they appear as supertypes of classes
Summary:
Flow is changing the behavior of object types to no longer be valid supertypes of classes. This replaces object types when they appear as supertypes of classes to be interfaces to avoid errors when this change rolls out.

Changelog: [Internal]

Reviewed By: pieterv

Differential Revision: D27193522

fbshipit-source-id: c3e3fca8a4cacd90770a95b773ff2c659774b9a6
2021-03-23 10:26:19 -07:00
Tim Yung 035718ba97 RN: Restore Deprecated Event Methods
Summary:
Restore deprecated event listener removal methods in order to minimize breaking changes for the next release. The methods will work, but they will not report a warning via `console.error`.

Changelog:
[General][Added] - `EventEmitter.removeListener` now emits a deprecation notice.
[General][Added] - Restored `AppState.removeEventListener` with a deprecation notice.
[General][Added] - Restored `Keyboard.removeEventListener` with a deprecation notice.
[General][Added] - Restored `Linking.removeEventListener` with a deprecation notice.

Reviewed By: nadiia, kacieb

Differential Revision: D26589441

fbshipit-source-id: 7d89982a182cf2163136e157d4c1beee91c30393
2021-03-10 16:06:26 -08:00
Hans Halverson d477f80113 Deploy Flow v0.146.0
Summary: Changelog: [Internal]

Reviewed By: mroch

Differential Revision: D26835439

fbshipit-source-id: 2607c3185485c8bd2c7e868dd2e3e0c06866f1f9
2021-03-06 11:37:57 -08:00
Tim Yung 3af0c84aa5 RN: Simplify `RCTDeviceEventEmitter`
Summary:
Simplifies `RCTDeviceEventEmitter` to simply be an `EventEmitter`.

The only thing special about it is that all native events are emitted on it and that `NativeEventEmitter` composes it.

Changelog:
[General][Removed] - Removed `RCTDeviceEventEmitter.sharedSubscribers`.

Reviewed By: RSNara

Differential Revision: D26163660

fbshipit-source-id: aedff8323d86947220fc293a74a19a3981fd875a
2021-02-17 12:20:26 -08:00
Tim Yung d39643b9de RN: Rewrite `NativeEventEmitter`
Summary:
Rewrites `NativeEventEmitter` to not extend `EventEmitter` and to compose `RCTDeviceEventEmitter` instead of (mis)using its exported `sharedSubscriber` property.

This makes it easier to reason about `NativeEventEmitter`. Also, the extraneous methods on `EventEmitter` are no longer inherited.

Changelog:
[General][Removed] - `NativeEventEmitter` no longer inherits from `EventEmitter`, so it no longer implements `removeListener` and `removeSubscription`. Instead, use the `remove()` method on the subscription object returned by `addListener`.

Reviewed By: rubennorte

Differential Revision: D26163562

fbshipit-source-id: c1aadb99bdefbaa36fece57ce74604e414f94d4d
2021-02-09 21:27:45 -08:00
Tim Yung c8c975f0d7 RN: Remove `RCTDeviceEventEmitter` Checks
Summary:
Removes the checks in `RCTDeviceEventEmitter` that were initially added to migrate call sites to other modules when `NativeEventEmitter` was introduced.

This set of checks is problematic for a few reasons:

1. Does not cover many other events that have since been introduced, so the small list covered is arbitrary.
2. Prevents composition of `RCTDeviceEventEmitter` in the implementation of those modules.
3. Code bloat.

Changelog:
[General][Removed] - `RCTDeviceEventEmitter` no longer throws for `SttatusBar`, `Keyboard`, and `AppState` events. However, you are still recommended to use the more appropriate modules for listening to these events.

Reviewed By: lunaleaps

Differential Revision: D26163602

fbshipit-source-id: 316287bfdf2947fe85d022a3f83a205e89c432ba
2021-02-03 22:04:40 -08:00
Micha Reiser 93377ff508 Remove "use strict" directive from ES Modules
Summary:
ES Modules implicitly enable strict mode. Adding the "use strict" directive is, therefore, not required.

This diff removes all "use strict" directives from ES modules.

Changelog:

[Internal]

Reviewed By: motiz88

Differential Revision: D26172715

fbshipit-source-id: 57957bcbb672c4c3e62b1db633cf425c1c9d6430
2021-02-02 11:12:56 -08:00
Tim Yung f5f47879b8 RN: Delete `NativeEventEmitter` Options
Summary:
Removes the `options` argument in the `NativeEventEmitter` constructor. It was only being used for an experimental flag that is no longer necessary.

Changelog:
[General][Removed] - Removed second optional argument of `NativeEventEmitter` constructor

Reviewed By: RSNara

Differential Revision: D26138239

fbshipit-source-id: 0481ce44f0464668e3a6e7ffaf079d17c87afd42
2021-02-01 17:50:21 -08:00
Rubén Norte fa406ac2aa Implement typed event emitters
Summary:
Adds types to Event Emitters and migrates the most relevant modules using them in `react-native`.

The most relevant file of this diff is `react-native/Libraries/vendor/emitter/__flowtests__/EventEmitter-flowtest.js` with the Flow tests showing and testing the behavior of the new types

Changelog: [Internal] Add types for Event Emitters and subclasses

Reviewed By: motiz88

Differential Revision: D25587936

fbshipit-source-id: feeb09f9ad15d383cdd82deaaaba0d12b94e868b
2021-01-07 03:19:04 -08:00
Rubén Norte c7463f0059 Add FlowFixMes for future violations of typed NativeEventEmitter
Summary:
Migrates all usages of `NativeEventEmitter` to `NativeEventEmitter<$FlowFixMe>`.

This prevents having to modify a very large number of files in the same change that adds support for typed events. It adds an unused typed parameter to `NativeEventEmitter` so we can change all usages to add `$FlowFixMe`.

Changelog: [Internal]

Reviewed By: nadiia

Differential Revision: D25575774

fbshipit-source-id: c7979e1502e980401d9c03456282eba333c1606d
2021-01-04 03:56:57 -08:00
Ramanpreet Nara dabca52f77 Stop calling RCTNetworking.(add|remove)Listeners?
Summary:
RCTNetworking.startObserving and RCTNetworking.stopObserving don't exist. The main purpose of RCTEventEmitter.addListener is to call these methods, and increment the `_listeners` counter, so that we can start dispatching events when `_listeners > 0`. In D24272560, I made RCTEventEmitter dispatch events even when _listeners <= 0. This is sufficient for us to stop calling these two RCTNetworking methods entirely.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24272663

fbshipit-source-id: de9c968bc71e6e6d69a22b934644e6dfa3266b3f
2020-10-14 21:05:38 -07:00
Tim Yung b11d6ecbb8 EventEmitter: Replace `listeners()` with `listenerCount()`
Summary:
Replaces the `listeners()` method on `EventEmitter` with a `listenerCount()` method.

Changelog:
[General][Removed] - Removed `listeners()` from `DeviceEventEmitter` and `NativeEventEmitter`.
[General][Added] - Added `listenerCount()` to `DeviceEventEmitter` and `NativeEventEmitter`.

Reviewed By: cpojer

Differential Revision: D22204156

fbshipit-source-id: 15029525aeef55de9934a4f319910e666ecbe1d8
2020-09-03 15:21:11 -07:00
Tim Yung 9a5ab9e366 EventEmitter: Default Export `{Native,RCTDevice}EventEmitter`
Summary:
Refactors `NativeEventEmitter` and `RCTDeviceEventEmitter` to be default exports.

Changelog:
[Internal]

Reviewed By: RSNara

Differential Revision: D22203918

fbshipit-source-id: 575b2baf1604d1a8a1bffd6d108c12f3f8415e0a
2020-08-27 17:52:44 -07:00
Tim Yung 4a1820dbdf EventEmitter: Import `{Native,RCTDevice}EventEmitter`
Summary:
Upgrades `require` expressions of `NativeEventEmitter` and `RCTDeviceEventEmitter` to `import`.

Changelog:
[Internal]

Reviewed By: cpojer

Differential Revision: D22203919

fbshipit-source-id: 4fdf01b66ba0501d0e0714931923531c97d29be2
2020-06-27 02:18:10 -07:00
Tim Yung 2933b887cd EventEmitter: Prefix Private Modules with `_`
Summary:
Renames `EventSubscription.js`, `EmitterSubscription.js`, and `EventSubscriptionVendor.js` to `_EventSubscription.js`, `_EmitterSubscription.js`, and `_EventSubscriptionVendor.js`, respectively.

This is to indicate that those files are implementation details and should not be directly referenced. Instead, the `EventSubscription` type exported from `EventEmitter.js` should be used.

The remaining stragglers that are importing `_EmitterSubscription.js` and `_EventSubscriptionVendor.js` after this commit will be cleaned up when `RCTDeviceEventEmitter` is refactored.

Changelog:
[Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: cpojer

Differential Revision: D22182310

fbshipit-source-id: 82be685f231395bd7b8e9986141b5df1367bec71
2020-06-23 13:50:26 -07:00
Tim Yung 70a73ca461 EventEmitter: Import `{Emitter => Event}Subscription`
Summary:
Changes dependents of `EmitterSubscription` to instead import the `EventSubscription` type from `EventEmitter.js`.

Changelog:
[Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: cpojer

Differential Revision: D22182309

fbshipit-source-id: 575f4c59248ef50182ddb33911f1e6f3ba88ec07
2020-06-23 13:50:26 -07:00
Tim Yung ab59e1819a EventEmitter: Upgrade from `require` to `import`
Summary:
Upgrades dependents of `EventEmitter`, `EventSubscription`, `EventSubscriptionVendor`, and `EmitterSubscription` to use `import` instead of `require`.

Changelog:
[Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: cpojer

Differential Revision: D22182312

fbshipit-source-id: e9444aa2728d89d52f577725f688871f7dbfba8a
2020-06-23 13:50:25 -07:00
George Zahariev 8553e1acc4 Exact-by-default codemod for react-native-github
Summary:
We are rolling out exact-by-default syntax to xplat/js.

I had to manually move around some comments to preserve proper placement.

Changelog: [Internal]

Reviewed By: jbrown215

Differential Revision: D18633611

fbshipit-source-id: 48f7468dcc55b1d00985419d035a61c6820b3abe
2019-11-21 09:42:57 -08:00
Logan Daniels 91f139b941 xplat/js/react-native-github
Reviewed By: panagosg7

Differential Revision: D16657770

fbshipit-source-id: 4e260842c838a35317515044c54ccf55a083da33
2019-08-09 10:11:15 -07:00
James Ide 0ee5f68929 Migrate "Libraries" from Haste to standard path-based requires (sans vendor & renderers) (#24749)
Summary:
This is the next step in moving RN towards standard path-based requires. All the requires in `Libraries` have been rewritten to use relative requires with a few exceptions, namely, `vendor` and `Renderer/oss` since those need to be changed upstream. This commit uses relative requires instead of `react-native/...` so that if Facebook were to stop syncing out certain folders and therefore remove code from the react-native package, internal code at Facebook would not need to change.

See the umbrella issue at https://github.com/facebook/react-native/issues/24316 for more detail.

[General] [Changed] - Migrate "Libraries" from Haste to standard path-based requires
Pull Request resolved: https://github.com/facebook/react-native/pull/24749

Differential Revision: D15258017

Pulled By: cpojer

fbshipit-source-id: a1f480ea36c05c659b6f37c8f02f6f9216d5a323
2019-05-08 08:48:59 -07:00
Brian Zhao 57c1a7add2 Remove MissingNativeRCTNetworkingShim; revert MissingNativeAppStateShim (#24380)
Summary:
`setupDevtools.js` is accessing `AppState.currentState` without checking its availability. In environments where 1) `__DEV__ == true`, and 2) no `RCTAppState` native module is provided thus resorting to `MissingNativeAppStateShim`, this will result in an exception:

```Cannot use 'AppState' module when native 'RCTAppState' is not included in the build. Either include it, or check 'AppState'.isAvailable before calling any methods.```

(Interestingly, `MissingNativeAppStateShim.currentState` did have a [default `null` value](118e88393e (diff-305b5180aa6ccc876ede6767de1fbfc4R192)) that was [later removed](a93b7a2da0 (diff-305b5180aa6ccc876ede6767de1fbfc4R186)).)

**Update**: Following cpojer's suggestion of reverting a93b7a2da0. Title also updated to reflect this.

[General] [Fixed] - Remove MissingNativeRCTNetworkingShim; revert MissingNativeAppStateShim
Pull Request resolved: https://github.com/facebook/react-native/pull/24380

Differential Revision: D14932658

Pulled By: cpojer

fbshipit-source-id: aef7ca566b3b8660eaed74a8ba3b6b0117b1200c
2019-04-15 10:47:53 -07:00
Christoph Nakazawa 4148976a83 Use `invariant` instead of `fbjs/lib/invariant`
Summary: This is one more step to remove `fbjs` from `react-native-github`. This changes both the internal and external code to use `invariant` from zertosh instead of the copy in fbjs.

Reviewed By: yungsters

Differential Revision: D13195941

fbshipit-source-id: 73564ca1715110e7da9c7ef56dc57374d61377e0
2018-12-03 00:07:02 -08:00
Héctor Ramos 1151c096da Update copyright headers to yearless format
Summary: This change drops the year from the copyright headers and the LICENSE file.

Reviewed By: yungsters

Differential Revision: D9727774

fbshipit-source-id: df4fc1e4390733fe774b1a160dd41b4a3d83302a
2018-09-11 15:33:07 -07:00
Wayne Cheng f536a0c268 Adding flow strict local to remaining possible files in xplat/JS
Summary:
ag -L --ignore __snapshots__ 'flow strict|noflow|generated|The controller you requested could not be found.' | ag '\.js$' | xargs ag -l 'flow' | sort > ~/temp
  cat ~/temp | xargs ag -L 'flow strict' | xargs sed -i '' 's/flow$/flow strict-local/'
  until flow check; do flow check --json | jq -r '.errors[].message[0].path' | sort | uniq | xargs hg revert; done

allow_many_files
The controller you requested could not be found.
The controller you requested could not be found.

Reviewed By: TheSavior

Differential Revision: D9004573

fbshipit-source-id: 936bd5741706b781be06bf08b6ad805a69407dfd
2018-08-09 08:54:44 -07:00
Eli White d01ab66b47 Prettier React Native Libraries
Reviewed By: sahrens

Differential Revision: D7961488

fbshipit-source-id: 05f9b8b0b91ae77f9040a5321ccc18f7c3c1ce9a
2018-05-10 19:10:38 -07:00
Rubén Norte d5e9e55fa3 Remove @providesModule from all modules
Summary:
This PR removes the need for having the `providesModule` tags in all the modules in the repository.

It configures Flow, Jest and Metro to get the module names from the filenames (`Libraries/Animated/src/nodes/AnimatedInterpolation.js` => `AnimatedInterpolation`)

* Checked the Flow configuration by running flow on the project root (no errors):

```
yarn flow
```

* Checked the Jest configuration by running the tests with a clean cache:

```
yarn jest --clearCache && yarn test
```

* Checked the Metro configuration by starting the server with a clean cache and requesting some bundles:

```
yarn run start --reset-cache
curl 'localhost:8081/IntegrationTests/AccessibilityManagerTest.bundle?platform=android'
curl 'localhost:8081/Libraries/Alert/Alert.bundle?platform=ios'
```

[INTERNAL] [FEATURE] [All] - Removed providesModule from all modules and configured tools.
Closes https://github.com/facebook/react-native/pull/18995

Reviewed By: mjesun

Differential Revision: D7729509

Pulled By: rubennorte

fbshipit-source-id: 892f760a05ce1fddb088ff0cd2e97e521fb8e825
2018-04-25 07:37:10 -07:00
Sophie Alpert 1490ab12ef Update license headers for MIT license
Summary:
Includes React Native and its dependencies Fresco, Metro, and Yoga. Excludes samples/examples/docs.

find: ^(?:( *)|( *(?:[\*~#]|::))( )? *)?Copyright (?:\(c\) )?(\d{4})\b.+Facebook[\s\S]+?BSD[\s\S]+?(?:this source tree|the same directory)\.$
replace: $1$2$3Copyright (c) $4-present, Facebook, Inc.\n$2\n$1$2$3This source code is licensed under the MIT license found in the\n$1$2$3LICENSE file in the root directory of this source tree.

Reviewed By: TheSavior, yungsters

Differential Revision: D7007050

fbshipit-source-id: 37dd6bf0ffec0923bfc99c260bb330683f35553e
2018-02-16 18:31:53 -08:00
Tim Yung 2fff445b13 RN: Improve NativeEventEmitter Flow Types
Reviewed By: fkgozali

Differential Revision: D6050987

fbshipit-source-id: 1c911bed23f7d26800aafed4b7e7c30a1197f64b
2017-10-13 08:04:17 -07:00
Eli White dd92dba3da Turn on Flow for EventEmitter
Reviewed By: sahrens

Differential Revision: D5732809

fbshipit-source-id: b8241120188b2b64af12249b2f00a43bea3b58a4
2017-08-30 11:52:28 -07:00
Pieter De Baets db3df3400a Breaking - make RCTDeviceEventEmitter warnings fatal
Reviewed By: davidaurelio

Differential Revision: D5469832

fbshipit-source-id: 1eb4ad3a2b3e1fa10d75e42d1d2f7baa291cb6f4
2017-07-24 03:47:59 -07:00
Spencer Ahrens 365aea3415 Libraries/Shared --> Libraries/www-shared, EventEmitter --> vendor/emitter
Reviewed By: fkgozali

Differential Revision: D5455575

fbshipit-source-id: 0eb4da4b1d8688b704f2f751143610e6ed836ce7
2017-07-21 09:40:15 -07:00
Alex Dvornikov 485bb70691 Allow lazy modules registration with the BatchedBridge
Reviewed By: javache

Differential Revision: D5181849

fbshipit-source-id: f63562c360488a9818605b25c1338214daac7411
2017-06-06 07:07:19 -07:00
Alex Dvornikov a93b7a2da0 Added stubs for some native modules
Reviewed By: javache

Differential Revision: D5111649

fbshipit-source-id: eef2f84556611dec01978d845b89fa145ec5d4db
2017-06-01 08:31:19 -07:00
Janic Duplessis 87b0378eb8 Native Animated - Restore, reorganize and add new tests
Summary:
Native Animated tests were removed a while back because they were failing, this restores the existing tests and reorganize / cleanup them. It also adds new ones so we have at least one test for each public API. These tests mostly assert that the native animated module is called with the proper args.
Closes https://github.com/facebook/react-native/pull/12775

Differential Revision: D4684968

Pulled By: ericvicenti

fbshipit-source-id: 4783d5edd08101cab7c0ce2eec4f3ccd0fbc1d27
2017-03-27 11:46:05 -07:00
David Aurelio 2b4762f184 Only use `EventValidator` in development mode
Summary: Only pulls in `EventValidator` for development mode, as warnings about invalid events are pointless in production builds.

Reviewed By: javache

Differential Revision: D4745852

fbshipit-source-id: dbab1026df35d54a82e1e620fac08304c58fbeae
2017-03-21 10:09:38 -07:00
David Aurelio a34956f2fb Remove `copyProperties`
Summary: remove `copyProperties` module, and replace the functionality with `Object.assign`

Reviewed By: javache

Differential Revision: D4745771

fbshipit-source-id: 2440620757e7539dbd7fd39f5920ac0b5b4183c5
2017-03-21 08:01:58 -07:00
Tim Yung 23331df5a4 RN: Cleanup OSS JS & Flow Declarations
Reviewed By: vjeux

Differential Revision: D4210763

fbshipit-source-id: 5abaa547100b8badd13bcf311ceffc5b4098d252
2016-11-20 17:58:29 -08:00
Tim Yung a3868722f8 Cleanup: Remove `@typechecks`
Reviewed By: spicyj

Differential Revision: D4010629

fbshipit-source-id: b243b2ca09cdfcaeec49b5f6850139d0461b80c5
2016-10-12 19:28:42 -07:00
Pieter De Baets 292cc82d0e Reorganize core JS files
Reviewed By: lexs

Differential Revision: D3987463

fbshipit-source-id: fa8f1d1bea7ed699120b9705ddc1c83767fcf8e4
2016-10-11 10:14:28 -07:00
David Aurelio 94666f16c7 Auto-fix lint errors
Reviewed By: bestander

Differential Revision: D3683952

fbshipit-source-id: 9484d0b0e86859e8edaca0da1aa13a667f200905
2016-08-09 06:43:46 -07:00
Eric Kreutzer 73bea8f7e6 Fixes EventEmitter#once arguments not getting passed to the listener
Summary:
Arrow functions do not have their own arguments. Fix EventEmitter#once to pass the correct arguments to the listener callback.
Closes https://github.com/facebook/react-native/pull/8479

Differential Revision: D3495086

Pulled By: javache

fbshipit-source-id: 4492d13bfb2cc255afdc41d39fbf2f35da6b7094
2016-06-28 16:13:21 -07:00
Rahul Jiresal 0e8c3ff463 Add a removeListener method to DeviceEventEmitter for Framework consi…
Summary:
The Framework is inconsistent in how listeners are removed in certain classes. This issue has been discussed in https://github.com/facebook/react-native/issues/6493.

For example,

**DeviceEventEmitter**

```javascript
/* Current */
this.keyboardHideObserver = DeviceEventEmitter.addListener('keyboardWillHide', this.keyboardWillHide);
this.keyboardHideObserver.remove();

/* Expected (maybe in addition to the current API) */
DeviceEventEmitter.addListener('keyboardWillHide', this.keyboardWillHide);
DeviceEventEmitter.removeListener('keyboardWillHide', this.keyboardWillHide);
```
**AppStateIOS**

```javascript
AppStateIOS.addEventListener('change', this.handleAppStateChange);
AppStateIOS.removeEventListener('change', this.handleAppStateChange);
```

The API should be consistent, and preferably should allow both ways of removing the listeners.

Currently, developers who tried to use the second way of removing the listeners get an error for function not found. Due to the lack of documenta
Closes https://github.com/facebook/react-native/pull/6884

Differential Revision: D3341235

Pulled By: nicklockwood

fbshipit-source-id: 87431e8b667f46ad002d4a6e3ca07cbc1e6b4007
2016-05-24 11:45:51 -07:00
Nick Lockwood d9737571c4 Updated AppState module to use new emitter system
Summary: AppState now subclasses NativeEventEmitter instead of using global RCTDeviceEventEmitter.

Reviewed By: javache

Differential Revision: D3310488

fbshipit-source-id: f0116599223f4411307385c0dab683659d8d63b6
2016-05-23 09:13:37 -07:00
Nick Lockwood 516bf7bd94 Fixed NativeEventListener deregistration
Summary:
The `EmitterSubscription.remove()` method was previously calling `this.subscriber.removeSubscription(this)` directly, bypassing the mechanism in `NativeEventEmitter` that keeps track of the number of subscriptions.

This meant that native event modules (subclasses of `RCTEventEmitter`) would keep sending events even after all the listeners had been removed. This wasn't a huge overhead, since these modules are singletons and only send one message over the bridge per event, regardless of the number of listeners, but it's still undesirable.

This fixes the problem by routing the `EmitterSubscription.remove()` method through the `EventEmitter` so that `NativeEventEmitter` can apply the additional native calls.

I've also improved the architecture so that each `NativeEventEmitter` uses its own `EventEmitter`, but they currently all still share the same `EventSubscriptionVendor` so that legacy code which registers events via `RCTDeviceEventEmitter` still works.

Reviewed By: vjeux

Differential Revision: D3292361

fbshipit-source-id: d60e881d50351523d2112473703bea826641cdef
2016-05-16 04:13:56 -07:00