Skip to content

Commit

Permalink
Use react-native's public interface where possible
Browse files Browse the repository at this point in the history
Instead of requiring specific files and bypassing the public interface, require react-native's exports where possible instead.
  • Loading branch information
ide committed Apr 10, 2019
1 parent 82ff7bd commit 7d90a08
Show file tree
Hide file tree
Showing 94 changed files with 277 additions and 265 deletions.
4 changes: 2 additions & 2 deletions RNTester/RCTTest/RCTSnapshotNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

'use strict';

const {requireNativeComponent} = require('react-native');

import type {SyntheticEvent} from '../../Libraries/Types/CoreEventTypes';
import type {ViewProps} from '../../Libraries/Components/View/ViewPropTypes';
import type {NativeComponent} from '../../Libraries/Renderer/shims/ReactNative';
Expand All @@ -28,8 +30,6 @@ type NativeProps = $ReadOnly<{|

type SnapshotViewNativeType = Class<NativeComponent<NativeProps>>;

const requireNativeComponent = require('../../Libraries/ReactNative/requireNativeComponent');

module.exports = ((requireNativeComponent(
'RCTSnapshot',
): any): SnapshotViewNativeType);
3 changes: 1 addition & 2 deletions RNTester/js/ARTExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {ART, Platform, View} = ReactNative;
const {ART, Platform, View} = require('react-native');

const {Surface, Path, Group, Shape} = ART;

Expand Down
5 changes: 1 addition & 4 deletions RNTester/js/AccessibilityAndroidExample.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {
AccessibilityInfo,
StyleSheet,
Text,
View,
ToastAndroid,
TouchableWithoutFeedback,
} = ReactNative;
} = require('react-native');

const RNTesterBlock = require('./RNTesterBlock');
const RNTesterPage = require('./RNTesterPage');
Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/AccessibilityExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {AccessibilityInfo, Text, View, TouchableOpacity, Alert} = ReactNative;
const {AccessibilityInfo, Text, View, TouchableOpacity, Alert} = require('react-native');

const RNTesterBlock = require('./RNTesterBlock');

Expand Down
7 changes: 4 additions & 3 deletions RNTester/js/AccessibilityIOSExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {AccessibilityInfo, Text, View, TouchableOpacity, Alert} = ReactNative;
const {Text, View, Alert} = require('react-native');

const RNTesterBlock = require('./RNTesterBlock');

Expand All @@ -34,7 +33,9 @@ class AccessibilityIOSExample extends React.Component<Props> {
<Text>Accessibility magic tap example</Text>
</View>
<View
onAccessibilityEscape={() => alert('onAccessibilityEscape success')}
onAccessibilityEscape={() =>
Alert.alert('onAccessibilityEscape success')
}
accessible={true}>
<Text>Accessibility escape example</Text>
</View>
Expand Down
8 changes: 4 additions & 4 deletions RNTester/js/ActionSheetIOSExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {
ActionSheetIOS,
StyleSheet,
Text,
View,
Alert,
NativeModules,
} = ReactNative;
findNodeHandle,
} = require('react-native');
const ScreenshotManager = NativeModules.ScreenshotManager;

const BUTTONS = ['Option 0', 'Option 1', 'Option 2', 'Delete', 'Cancel'];
Expand Down Expand Up @@ -128,7 +128,7 @@ class ActionSheetAnchorExample extends React.Component<
cancelButtonIndex: CANCEL_INDEX,
destructiveButtonIndex: DESTRUCTIVE_INDEX,
anchor: this.anchorRef.current
? ReactNative.findNodeHandle(this.anchorRef.current)
? findNodeHandle(this.anchorRef.current)
: undefined,
},
buttonIndex => {
Expand Down Expand Up @@ -263,7 +263,7 @@ class ShareScreenshotAnchorExample extends React.Component<
url: uri,
excludedActivityTypes: ['com.apple.UIKit.activity.PostToTwitter'],
anchor: this.anchorRef.current
? ReactNative.findNodeHandle(this.anchorRef.current)
? findNodeHandle(this.anchorRef.current)
: undefined,
},
error => Alert.alert('Error', error),
Expand Down
9 changes: 7 additions & 2 deletions RNTester/js/AlertExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {Alert, StyleSheet, Text, TouchableHighlight, View} = ReactNative;
const {
Alert,
StyleSheet,
Text,
TouchableHighlight,
View,
} = require('react-native');

const RNTesterBlock = require('./RNTesterBlock');

Expand Down
9 changes: 7 additions & 2 deletions RNTester/js/AlertIOSExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {StyleSheet, View, Text, TouchableHighlight, Alert} = ReactNative;
const {
StyleSheet,
View,
Text,
TouchableHighlight,
Alert,
} = require('react-native');

const {SimpleAlertExampleBlock} = require('./AlertExample');

Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/AnimatedExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {Animated, Easing, StyleSheet, Text, View} = ReactNative;
const {Animated, Easing, StyleSheet, Text, View} = require('react-native');
const RNTesterButton = require('./RNTesterButton');

const styles = StyleSheet.create({
Expand Down
9 changes: 7 additions & 2 deletions RNTester/js/AnimatedGratuitousApp/AnExApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {Animated, LayoutAnimation, PanResponder, StyleSheet, View} = ReactNative;
const {
Animated,
LayoutAnimation,
PanResponder,
StyleSheet,
View,
} = require('react-native');

const AnExSet = require('./AnExSet');

Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/AnimatedGratuitousApp/AnExBobble.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {Animated, PanResponder, StyleSheet, View} = ReactNative;
const {Animated, PanResponder, StyleSheet, View} = require('react-native');

const NUM_BOBBLES = 5;
const RAD_EACH = Math.PI / 2 / (NUM_BOBBLES - 2);
Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/AnimatedGratuitousApp/AnExChained.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {Animated, PanResponder, StyleSheet, View} = ReactNative;
const {Animated, PanResponder, StyleSheet, View} = require('react-native');

class AnExChained extends React.Component<Object, any> {
constructor(props: Object) {
Expand Down
10 changes: 8 additions & 2 deletions RNTester/js/AnimatedGratuitousApp/AnExScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {Animated, Image, ScrollView, StyleSheet, Text, View} = ReactNative;
const {
Animated,
Image,
ScrollView,
StyleSheet,
Text,
View,
} = require('react-native');

class AnExScroll extends React.Component<$FlowFixMeProps, any> {
state: any = {scrollX: new Animated.Value(0)};
Expand Down
9 changes: 7 additions & 2 deletions RNTester/js/AnimatedGratuitousApp/AnExSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {Animated, PanResponder, StyleSheet, Text, View} = ReactNative;
const {
Animated,
PanResponder,
StyleSheet,
Text,
View,
} = require('react-native');

const AnExBobble = require('./AnExBobble');
const AnExChained = require('./AnExChained');
Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/AnimatedGratuitousApp/AnExTilt.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {Animated, PanResponder, StyleSheet} = ReactNative;
const {Animated, PanResponder, StyleSheet} = require('react-native');

class AnExTilt extends React.Component<Object, any> {
constructor(props: Object) {
Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/AppStateExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {AppState, Text, View} = ReactNative;
const {AppState, Text, View} = require('react-native');

class AppStateSubscription extends React.Component<
$FlowFixMeProps,
Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/AssetScaledImageExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {Image, StyleSheet, View, ScrollView} = ReactNative;
const {Image, StyleSheet, View, ScrollView} = require('react-native');

import type {PhotoIdentifier} from '../../Libraries/CameraRoll/CameraRoll';

Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/AsyncStorageExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {AsyncStorage, PickerIOS, Text, View} = ReactNative;
const {AsyncStorage, PickerIOS, Text, View} = require('react-native');
const PickerItemIOS = PickerIOS.Item;

const STORAGE_KEY = '@AsyncStorageExample:key';
Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/BorderExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {StyleSheet, View} = ReactNative;
const {StyleSheet, View} = require('react-native');

const styles = StyleSheet.create({
box: {
Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/BoxShadowExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {Image, StyleSheet, View} = ReactNative;
const {Image, StyleSheet, View} = require('react-native');

const styles = StyleSheet.create({
box: {
Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/ButtonExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {Alert, Button, View, StyleSheet} = ReactNative;
const {Alert, Button, View, StyleSheet} = require('react-native');

function onButtonPress(buttonName) {
Alert.alert(`${buttonName} has been pressed!`);
Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/CameraRollExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {
CameraRoll,
Image,
Expand All @@ -20,7 +19,7 @@ const {
Text,
View,
TouchableOpacity,
} = ReactNative;
} = require('react-native');

const invariant = require('invariant');

Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/CameraRollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {
ActivityIndicator,
Alert,
Expand All @@ -22,7 +21,7 @@ const {
Platform,
StyleSheet,
View,
} = ReactNative;
} = require('react-native');

const groupByEveryN = require('../../Libraries/Utilities/groupByEveryN');
const logError = require('../../Libraries/Utilities/logError');
Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/CheckBoxExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {CheckBox, Text, View, StyleSheet} = ReactNative;
const {CheckBox, Text, View, StyleSheet} = require('react-native');

type BasicState = {|
trueCheckBoxIsOn: boolean,
Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/ClipboardExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {Clipboard, View, Text, StyleSheet} = ReactNative;
const {Clipboard, View, Text, StyleSheet} = require('react-native');

type Props = $ReadOnly<{||}>;
type State = {|
Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/DatePickerAndroidExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {
DatePickerAndroid,
StyleSheet,
Text,
TouchableWithoutFeedback,
} = ReactNative;
} = require('react-native');

const RNTesterBlock = require('./RNTesterBlock');
const RNTesterPage = require('./RNTesterPage');
Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/DatePickerIOSExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {DatePickerIOS, StyleSheet, Text, View} = ReactNative;
const {DatePickerIOS, StyleSheet, Text, View} = require('react-native');

type State = {|
date: Date,
Expand Down
3 changes: 1 addition & 2 deletions RNTester/js/DimensionsExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
'use strict';

const React = require('react');
const ReactNative = require('react-native');
const {Dimensions, Text, View} = ReactNative;
const {Dimensions, Text, View} = require('react-native');

class DimensionsSubscription extends React.Component<
{dim: string},
Expand Down
4 changes: 1 addition & 3 deletions RNTester/js/FlatListExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@

import type {Item} from './ListExampleShared';

const Alert = require('../../Libraries/Alert/Alert');
const React = require('react');
const ReactNative = require('react-native');
const {Animated, StyleSheet, View} = ReactNative;
const {Alert, Animated, StyleSheet, View} = require('react-native');

const RNTesterPage = require('./RNTesterPage');

Expand Down
Loading

0 comments on commit 7d90a08

Please sign in to comment.