Skip to content

Commit 9e0c058

Browse files
lukewalczakmichalchudziak
authored andcommitted
Refactor imports exports (#135)
* Refactor import along with exports * Change imports in example * Fix flow
1 parent 10d6a96 commit 9e0c058

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

example/SliderExample.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111
'use strict';
1212

13-
const React = require('react');
14-
const {Text, StyleSheet, View} = require('react-native');
15-
const Slider = require('@react-native-community/slider');
13+
import React from 'react';
14+
import {Text, StyleSheet, View} from 'react-native';
15+
import Slider from '@react-native-community/slider';
1616

17+
import type {Element} from 'react';
1718
class SliderExample extends React.Component<$FlowFixMeProps, $FlowFixMeState> {
1819
static defaultProps = {
1920
value: 0,
@@ -113,43 +114,43 @@ exports.description = 'Slider input for numeric values';
113114
exports.examples = [
114115
{
115116
title: 'Default settings',
116-
render(): React.Element<any> {
117+
render(): Element<any> {
117118
return <SliderExample />;
118119
},
119120
},
120121
{
121122
title: 'Initial value: 0.5',
122-
render(): React.Element<any> {
123+
render(): Element<any> {
123124
return <SliderExample value={0.5} />;
124125
},
125126
},
126127
{
127128
title: 'minimumValue: -1, maximumValue: 2',
128-
render(): React.Element<any> {
129+
render(): Element<any> {
129130
return <SliderExample minimumValue={-1} maximumValue={2} />;
130131
},
131132
},
132133
{
133134
title: 'step: 0.25',
134-
render(): React.Element<any> {
135+
render(): Element<any> {
135136
return <SliderExample step={0.25} />;
136137
},
137138
},
138139
{
139140
title: 'onSlidingStart',
140-
render(): React.Element<any> {
141+
render(): Element<any> {
141142
return <SlidingStartExample />;
142143
},
143144
},
144145
{
145146
title: 'onSlidingComplete',
146-
render(): React.Element<any> {
147+
render(): Element<any> {
147148
return <SlidingCompleteExample />;
148149
},
149150
},
150151
{
151152
title: 'Custom min/max track tint color',
152-
render(): React.Element<any> {
153+
render(): Element<any> {
153154
return (
154155
<SliderExample
155156
minimumTrackTintColor={'blue'}
@@ -161,27 +162,27 @@ exports.examples = [
161162
},
162163
{
163164
title: 'Custom thumb tint color',
164-
render(): React.Element<any> {
165+
render(): Element<any> {
165166
return <SliderExample thumbTintColor={'blue'} />;
166167
},
167168
},
168169
{
169170
title: 'Custom thumb image',
170-
render(): React.Element<any> {
171+
render(): Element<any> {
171172
return <SliderExample thumbImage={require('./uie_thumb_big.png')} />;
172173
},
173174
},
174175
{
175176
title: 'Custom track image',
176177
platform: 'ios',
177-
render(): React.Element<any> {
178+
render(): Element<any> {
178179
return <SliderExample trackImage={require('./slider.png')} />;
179180
},
180181
},
181182
{
182183
title: 'Custom min/max track image',
183184
platform: 'ios',
184-
render(): React.Element<any> {
185+
render(): Element<any> {
185186
return (
186187
<SliderExample
187188
minimumTrackImage={require('./slider-left.png')}
@@ -192,7 +193,7 @@ exports.examples = [
192193
},
193194
{
194195
title: 'Inverted slider direction',
195-
render(): React.Element<any> {
196+
render(): Element<any> {
196197
return <SliderExample value={0.6} inverted />;
197198
},
198199
},

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "example",
44
"version": "0.0.1",
55
"scripts": {
6-
"start": "node node_modules/react-native/local-cli/cli.js start",
6+
"start": "node ../node_modules/react-native/local-cli/cli.js start",
77
"run:android": "react-native run-android",
88
"run:ios": "react-native run-ios"
99
},

src/js/RNCSliderNativeComponent.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
'use strict';
1212

13-
const {requireNativeComponent} = require('react-native');
13+
import {requireNativeComponent} from 'react-native';
1414

1515
import type {ColorValue} from 'react-native/Libraries/StyleSheet/StyleSheetTypes';
1616
import type {ImageSource} from 'react-native/Libraries/Image/ImageSource';
@@ -50,4 +50,7 @@ type NativeProps = $ReadOnly<{|
5050

5151
type RNCSliderType = Class<NativeComponent<NativeProps>>;
5252

53-
module.exports = ((requireNativeComponent('RNCSlider'): any): RNCSliderType);
53+
const RNCSliderNativeComponent = ((requireNativeComponent(
54+
'RNCSlider',
55+
): any): RNCSliderType);
56+
export default RNCSliderNativeComponent;

src/js/Slider.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111
'use strict';
1212

13-
const React = require('react');
14-
const {Image, Platform, StyleSheet} = require('react-native');
15-
const RCTSliderNativeComponent = require('./RNCSliderNativeComponent');
13+
import React from 'react';
14+
import {Image, Platform, StyleSheet} from 'react-native';
15+
import RCTSliderNativeComponent from './RNCSliderNativeComponent';
1616

17+
import type {Ref} from 'react';
1718
import type {NativeComponent} from 'react-native/Libraries/Renderer/shims/ReactNative';
1819
import type {ImageSource} from 'react-native/Libraries/Image/ImageSource';
1920
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';
@@ -208,9 +209,9 @@ type Props = $ReadOnly<{|
208209
*```
209210
*
210211
*/
211-
const Slider = (
212+
const SliderComponent = (
212213
props: Props,
213-
forwardedRef?: ?React.Ref<typeof RCTSliderNativeComponent>,
214+
forwardedRef?: ?Ref<typeof RCTSliderNativeComponent>,
214215
) => {
215216
const style = StyleSheet.compose(
216217
styles.slider,
@@ -266,7 +267,7 @@ const Slider = (
266267
);
267268
};
268269

269-
const SliderWithRef = React.forwardRef(Slider);
270+
const SliderWithRef = React.forwardRef(SliderComponent);
270271

271272
/* $FlowFixMe(>=0.89.0 site=react_native_fb) This comment suppresses an error
272273
* found when Flow v0.89 was deployed. To see the error, delete this comment
@@ -296,4 +297,5 @@ if (Platform.OS === 'ios') {
296297
/* $FlowFixMe(>=0.89.0 site=react_native_fb) This comment suppresses an error
297298
* found when Flow v0.89 was deployed. To see the error, delete this comment
298299
* and run Flow. */
299-
module.exports = (SliderWithRef: Class<NativeComponent<Props>>);
300+
const Slider = (SliderWithRef: Class<NativeComponent<Props>>);
301+
export default Slider;

0 commit comments

Comments
 (0)