forked from maxs15/react-native-spinkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·84 lines (70 loc) · 2.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React from 'react'
import ReactNative from 'react-native'
import PropTypes from 'prop-types';
var {
NativeModules,
processColor,
requireNativeComponent,
View
} = ReactNative;
var RNSpinkit = null;
class Spinkit extends React.Component {
static propTypes = {
type: PropTypes.string,
/**
* @prop color
* @NOTE This is typically passed as a string, but technically can also be
* a number (see https://facebook.github.io/react/docs/typechecking-with-proptypes.html).
* In addition, allowing a number prop type eliminates the PropType warning
* React Native will throw if passing a string into this component but a
* different type (number) down to the native module.
*/
color: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
size: PropTypes.number,
isVisible: PropTypes.bool,
testID: PropTypes.string,
accessibilityComponentType: PropTypes.string,
accessibilityLabel: PropTypes.string,
accessibilityLiveRegion: PropTypes.string,
renderToHardwareTextureAndroid: PropTypes.bool,
importantForAccessibility: PropTypes.string,
onLayout: PropTypes.func,
style: PropTypes.object,
};
static defaultProps = {
size: 37,
color: "#000000",
isVisible: true
};
render() {
if (!this.props.isVisible) return <View/>;
var size = {height: this.props.size, width: this.props.size};
// In order to handle all the color specifications allowed in React Native
// as a whole, we need to call processColor here, and can pass in the
// resulting number directly. RCTConvert will be called on iOS to parse
// into #AARRGGBB form; on Android, this int can be used directly for
// setting the color.
var colorNumber = processColor(this.props.color);
return (
<RNSpinkit
type={String(this.props.type)}
size={parseInt(this.props.size)}
color={colorNumber}
style={[size, this.props.style]}/>
);
}
}
// Since RNPM does not recognize `requireNativeComponent`, so we have to
// add this line, and RNPM will link native modules automatically
NativeModules.RNSpinkit;
// Native component
RNSpinkit = requireNativeComponent(
'RNSpinkit',
Spinkit,
{
nativeOnly: {
'nativeID': true
}
}
);
module.exports = Spinkit;