Skip to content

Commit 2de0323

Browse files
bestanderFacebook Github Bot 6
authored andcommitted
Reverted commit D3339945
Summary: Updated networking and geolocation to use the new events system. Reviewed By: javache Differential Revision: D3339945 fbshipit-source-id: 01d307cf8a0aea3a404c87c6205132c42290abb1
1 parent 8876eaa commit 2de0323

27 files changed

+340
-229
lines changed

Examples/UIExplorer/AppStateExample.js

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
/**
2-
* Copyright (c) 2013-present, Facebook, Inc.
3-
* All rights reserved.
4-
*
5-
* This source code is licensed under the BSD-style license found in the
6-
* LICENSE file in the root directory of this source tree. An additional grant
7-
* of patent rights can be found in the PATENTS file in the same directory.
8-
*
92
* The examples provided by Facebook are for non-commercial testing and
103
* evaluation purposes only.
114
*
@@ -23,9 +16,9 @@
2316
*/
2417
'use strict';
2518

26-
const React = require('react');
27-
const ReactNative = require('react-native');
28-
const {
19+
var React = require('react');
20+
var ReactNative = require('react-native');
21+
var {
2922
AppState,
3023
Text,
3124
View
@@ -36,19 +29,13 @@ var AppStateSubscription = React.createClass({
3629
return {
3730
appState: AppState.currentState,
3831
previousAppStates: [],
39-
memoryWarnings: 0,
4032
};
4133
},
4234
componentDidMount: function() {
4335
AppState.addEventListener('change', this._handleAppStateChange);
44-
AppState.addEventListener('memoryWarning', this._handleMemoryWarning);
4536
},
4637
componentWillUnmount: function() {
4738
AppState.removeEventListener('change', this._handleAppStateChange);
48-
AppState.removeEventListener('memoryWarning', this._handleMemoryWarning);
49-
},
50-
_handleMemoryWarning: function() {
51-
this.setState({memoryWarnings: this.state.memoryWarnings + 1});
5239
},
5340
_handleAppStateChange: function(appState) {
5441
var previousAppStates = this.state.previousAppStates.slice();
@@ -59,13 +46,6 @@ var AppStateSubscription = React.createClass({
5946
});
6047
},
6148
render() {
62-
if (this.props.showMemoryWarnings) {
63-
return (
64-
<View>
65-
<Text>{this.state.memoryWarnings}</Text>
66-
</View>
67-
);
68-
}
6949
if (this.props.showCurrentOnly) {
7050
return (
7151
<View>
@@ -98,10 +78,4 @@ exports.examples = [
9878
title: 'Previous states:',
9979
render(): ReactElement { return <AppStateSubscription showCurrentOnly={false} />; }
10080
},
101-
{
102-
platform: 'ios',
103-
title: 'Memory Warnings',
104-
description: 'In the IOS simulator, hit Shift+Command+M to simulate a memory warning.',
105-
render(): ReactElement { return <AppStateSubscription showMemoryWarnings={true} />; }
106-
},
10781
];
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* The examples provided by Facebook are for non-commercial testing and
3+
* evaluation purposes only.
4+
*
5+
* Facebook reserves all rights not expressly granted.
6+
*
7+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
8+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9+
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
10+
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
11+
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
12+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13+
*
14+
* @providesModule AppStateIOSExample
15+
* @flow
16+
*/
17+
'use strict';
18+
19+
var React = require('react');
20+
var ReactNative = require('react-native');
21+
var {
22+
AppStateIOS,
23+
Text,
24+
View
25+
} = ReactNative;
26+
27+
var AppStateSubscription = React.createClass({
28+
getInitialState() {
29+
return {
30+
appState: AppStateIOS.currentState,
31+
previousAppStates: [],
32+
memoryWarnings: 0,
33+
};
34+
},
35+
componentDidMount: function() {
36+
AppStateIOS.addEventListener('change', this._handleAppStateChange);
37+
AppStateIOS.addEventListener('memoryWarning', this._handleMemoryWarning);
38+
},
39+
componentWillUnmount: function() {
40+
AppStateIOS.removeEventListener('change', this._handleAppStateChange);
41+
AppStateIOS.removeEventListener('memoryWarning', this._handleMemoryWarning);
42+
},
43+
_handleMemoryWarning: function() {
44+
this.setState({memoryWarnings: this.state.memoryWarnings + 1});
45+
},
46+
_handleAppStateChange: function(appState) {
47+
var previousAppStates = this.state.previousAppStates.slice();
48+
previousAppStates.push(this.state.appState);
49+
this.setState({
50+
appState,
51+
previousAppStates,
52+
});
53+
},
54+
render() {
55+
if (this.props.showMemoryWarnings) {
56+
return (
57+
<View>
58+
<Text>{this.state.memoryWarnings}</Text>
59+
</View>
60+
);
61+
}
62+
if (this.props.showCurrentOnly) {
63+
return (
64+
<View>
65+
<Text>{this.state.appState}</Text>
66+
</View>
67+
);
68+
}
69+
return (
70+
<View>
71+
<Text>{JSON.stringify(this.state.previousAppStates)}</Text>
72+
</View>
73+
);
74+
}
75+
});
76+
77+
exports.title = 'AppStateIOS';
78+
exports.description = 'iOS app background status';
79+
exports.examples = [
80+
{
81+
title: 'AppStateIOS.currentState',
82+
description: 'Can be null on app initialization',
83+
render() { return <Text>{AppStateIOS.currentState}</Text>; }
84+
},
85+
{
86+
title: 'Subscribed AppStateIOS:',
87+
description: 'This changes according to the current state, so you can only ever see it rendered as "active"',
88+
render(): ReactElement { return <AppStateSubscription showCurrentOnly={true} />; }
89+
},
90+
{
91+
title: 'Previous states:',
92+
render(): ReactElement { return <AppStateSubscription showCurrentOnly={false} />; }
93+
},
94+
{
95+
title: 'Memory Warnings',
96+
description: 'In the simulator, hit Shift+Command+M to simulate a memory warning.',
97+
render(): ReactElement { return <AppStateSubscription showMemoryWarnings={true} />; }
98+
},
99+
];

Examples/UIExplorer/UIExplorerList.ios.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ const APIExamples: Array<UIExplorerExample> = [
171171
key: 'AnExApp',
172172
module: require('./AnimatedGratuitousApp/AnExApp'),
173173
},
174+
{
175+
key: 'AppStateIOSExample',
176+
module: require('./AppStateIOSExample'),
177+
},
174178
{
175179
key: 'AppStateExample',
176180
module: require('./AppStateExample'),

Examples/UIExplorer/UIExplorerUnitTests/RCTEventDispatcherTests.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ - (void)testLegacyEventsAreImmediatelyDispatched
105105

106106
#pragma clang diagnostic push
107107
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
108+
108109
[_eventDispatcher sendDeviceEventWithName:_eventName body:_body];
110+
109111
#pragma clang diagnostic pop
110112

111113
[_bridge verify];

Examples/UIExplorer/XHRExample.ios.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
/**
2-
* Copyright (c) 2013-present, Facebook, Inc.
3-
* All rights reserved.
4-
*
5-
* This source code is licensed under the BSD-style license found in the
6-
* LICENSE file in the root directory of this source tree. An additional grant
7-
* of patent rights can be found in the PATENTS file in the same directory.
8-
*
92
* The examples provided by Facebook are for non-commercial testing and
103
* evaluation purposes only.
114
*
@@ -28,7 +21,7 @@ var {
2821
AlertIOS,
2922
CameraRoll,
3023
Image,
31-
Linking,
24+
LinkingIOS,
3225
ProgressViewIOS,
3326
StyleSheet,
3427
Text,
@@ -222,7 +215,7 @@ class FormUploader extends React.Component {
222215
return;
223216
}
224217
var url = xhr.responseText.slice(index).split('\n')[0];
225-
Linking.openURL(url);
218+
LinkingIOS.openURL(url);
226219
};
227220
var formdata = new FormData();
228221
if (this.state.randomPhoto) {

Libraries/Geolocation/Geolocation.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@
1111
*/
1212
'use strict';
1313

14-
const NativeEventEmitter = require('NativeEventEmitter');
15-
const RCTLocationObserver = require('NativeModules').LocationObserver;
14+
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
15+
var RCTLocationObserver = require('NativeModules').LocationObserver;
1616

17-
const invariant = require('fbjs/lib/invariant');
18-
const logError = require('logError');
19-
const warning = require('fbjs/lib/warning');
20-
21-
const LocationEventEmitter = new NativeEventEmitter(RCTLocationObserver);
17+
var invariant = require('fbjs/lib/invariant');
18+
var logError = require('logError');
19+
var warning = require('fbjs/lib/warning');
2220

2321
var subscriptions = [];
22+
2423
var updatesEnabled = false;
2524

2625
type GeoOptions = {
@@ -81,11 +80,11 @@ var Geolocation = {
8180
}
8281
var watchID = subscriptions.length;
8382
subscriptions.push([
84-
LocationEventEmitter.addListener(
83+
RCTDeviceEventEmitter.addListener(
8584
'geolocationDidChange',
8685
success
8786
),
88-
error ? LocationEventEmitter.addListener(
87+
error ? RCTDeviceEventEmitter.addListener(
8988
'geolocationError',
9089
error
9190
) : null,

Libraries/Geolocation/RCTLocationObserver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10-
#import "RCTEventEmitter.h"
10+
#import "RCTBridgeModule.h"
1111

12-
@interface RCTLocationObserver : RCTEventEmitter
12+
@interface RCTLocationObserver : NSObject<RCTBridgeModule>
1313

1414
@end

Libraries/Geolocation/RCTLocationObserver.m

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ @implementation RCTLocationObserver
113113

114114
RCT_EXPORT_MODULE()
115115

116+
@synthesize bridge = _bridge;
117+
116118
#pragma mark - Lifecycle
117119

118120
- (void)dealloc
@@ -126,13 +128,9 @@ - (dispatch_queue_t)methodQueue
126128
return dispatch_get_main_queue();
127129
}
128130

129-
- (NSArray<NSString *> *)supportedEvents
130-
{
131-
return @[@"geolocationDidChange", @"geolocationError"];
132-
}
133-
134131
#pragma mark - Private API
135132

133+
136134
- (void)beginLocationUpdatesWithDesiredAccuracy:(CLLocationAccuracy)desiredAccuracy distanceFilter:(CLLocationDistance)distanceFilter
137135
{
138136
if (!_locationManager) {
@@ -281,7 +279,11 @@ - (void)locationManager:(CLLocationManager *)manager
281279

282280
// Send event
283281
if (_observingLocation) {
284-
[self sendEventWithName:@"geolocationDidChange" body:_lastLocationEvent];
282+
#pragma clang diagnostic push
283+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
284+
[_bridge.eventDispatcher sendDeviceEventWithName:@"geolocationDidChange"
285+
body:_lastLocationEvent];
286+
#pragma clang diagnostic pop
285287
}
286288

287289
// Fire all queued callbacks
@@ -322,7 +324,11 @@ - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *
322324

323325
// Send event
324326
if (_observingLocation) {
325-
[self sendEventWithName:@"geolocationError" body:jsError];
327+
#pragma clang diagnostic push
328+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
329+
[_bridge.eventDispatcher sendDeviceEventWithName:@"geolocationError"
330+
body:jsError];
331+
#pragma clang diagnostic pop
326332
}
327333

328334
// Fire all queued error callbacks

Libraries/LinkingIOS/RCTLinkingManager.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,8 @@ + (BOOL)application:(UIApplication *)application
8888

8989
- (void)handleOpenURLNotification:(NSNotification *)notification
9090
{
91-
#pragma clang diagnostic push
92-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
9391
[_bridge.eventDispatcher sendDeviceEventWithName:@"openURL"
9492
body:notification.userInfo];
95-
#pragma clang diagnostic pop
9693
}
9794

9895
RCT_EXPORT_METHOD(openURL:(NSURL *)URL

Libraries/Network/NetInfo.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
'use strict';
1313

1414
const Map = require('Map');
15-
const NativeEventEmitter = require('NativeEventEmitter');
1615
const NativeModules = require('NativeModules');
1716
const Platform = require('Platform');
17+
const RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
1818
const RCTNetInfo = NativeModules.NetInfo;
1919
const deprecatedCallback = require('deprecatedCallback');
2020

21-
const NetInfoEventEmitter = new NativeEventEmitter(RCTNetInfo);
22-
2321
const DEVICE_CONNECTIVITY_EVENT = 'networkStatusDidChange';
2422

2523
type ChangeEventName = $Enum<{
@@ -178,7 +176,7 @@ const NetInfo = {
178176
eventName: ChangeEventName,
179177
handler: Function
180178
): {remove: () => void} {
181-
const listener = NetInfoEventEmitter.addListener(
179+
const listener = RCTDeviceEventEmitter.addListener(
182180
DEVICE_CONNECTIVITY_EVENT,
183181
(appStateData) => {
184182
handler(appStateData.network_info);

0 commit comments

Comments
 (0)