@react-native-hero/spin 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -1
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/github/reactnativehero/spin/RNTSpinManager.kt +11 -11
- package/index.js +6 -0
- package/js/Spin.android.js +16 -2
- package/js/Spin.ios.js +5 -2
- package/js/size.js +2 -0
- package/package.json +1 -1
- package/android/src/main/java/com/github/reactnativehero/spin/SpinView.kt +0 -33
package/README.md
CHANGED
|
@@ -1 +1,41 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @react-native-hero/spin
|
|
2
|
+
|
|
3
|
+
## Getting started
|
|
4
|
+
|
|
5
|
+
Install the library using either Yarn:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
yarn add @react-native-hero/spin
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
or npm:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
npm install --save @react-native-hero/spin
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Link
|
|
18
|
+
|
|
19
|
+
For android, the package will be linked automatically on build.
|
|
20
|
+
|
|
21
|
+
- React Native <= 0.59
|
|
22
|
+
|
|
23
|
+
run the following command to link the package:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
$ react-native link @react-native-hero/spin
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Example
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import {
|
|
33
|
+
SIZE,
|
|
34
|
+
Spin,
|
|
35
|
+
} from '@react-native-hero/spin'
|
|
36
|
+
|
|
37
|
+
<Spin
|
|
38
|
+
size={SIZE.SMALL}
|
|
39
|
+
color="#999"
|
|
40
|
+
/>
|
|
41
|
+
```
|
package/android/build.gradle
CHANGED
|
@@ -3,8 +3,8 @@ buildscript {
|
|
|
3
3
|
def kotlinVersion = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : '1.3.40'
|
|
4
4
|
|
|
5
5
|
repositories {
|
|
6
|
-
jcenter()
|
|
7
6
|
google()
|
|
7
|
+
mavenCentral()
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
dependencies {
|
|
@@ -39,4 +39,4 @@ dependencies {
|
|
|
39
39
|
implementation "com.github.ybq:Android-SpinKit:${safeExtGet('spinkitVersion', '1.2.0')}"
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
apply plugin: 'kotlin-android'
|
|
42
|
+
apply plugin: 'kotlin-android'
|
|
@@ -4,25 +4,25 @@ import com.facebook.react.bridge.ReactApplicationContext
|
|
|
4
4
|
import com.facebook.react.uimanager.SimpleViewManager
|
|
5
5
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
6
6
|
import com.facebook.react.uimanager.annotations.ReactProp
|
|
7
|
+
import com.github.ybq.android.spinkit.SpinKitView
|
|
8
|
+
import com.github.ybq.android.spinkit.style.FadingCircle
|
|
7
9
|
|
|
8
|
-
class RNTSpinManager(private val reactAppContext: ReactApplicationContext) : SimpleViewManager<
|
|
10
|
+
class RNTSpinManager(private val reactAppContext: ReactApplicationContext) : SimpleViewManager<SpinKitView>() {
|
|
9
11
|
|
|
10
12
|
override fun getName(): String {
|
|
11
13
|
return "RNTSpin"
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
override fun createViewInstance(reactContext: ThemedReactContext):
|
|
15
|
-
|
|
16
|
+
override fun createViewInstance(reactContext: ThemedReactContext): SpinKitView {
|
|
17
|
+
val spin = SpinKitView(reactContext)
|
|
18
|
+
val style = FadingCircle()
|
|
19
|
+
spin.setIndeterminateDrawable(style)
|
|
20
|
+
return spin
|
|
16
21
|
}
|
|
17
22
|
|
|
18
|
-
@ReactProp(name = "size")
|
|
19
|
-
fun setSize(view: SpinView, size: Int) {
|
|
20
|
-
view.size = size
|
|
21
|
-
}
|
|
22
|
-
|
|
23
23
|
@ReactProp(name = "color", customType = "Color")
|
|
24
|
-
fun setColor(view:
|
|
25
|
-
view.color
|
|
24
|
+
fun setColor(view: SpinKitView, color: Int) {
|
|
25
|
+
view.setColor(color)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
}
|
|
28
|
+
}
|
package/index.js
CHANGED
package/js/Spin.android.js
CHANGED
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
|
|
9
9
|
import PropTypes from 'prop-types'
|
|
10
10
|
|
|
11
|
+
import { SMALL } from './size'
|
|
12
|
+
|
|
11
13
|
class Spin extends PureComponent {
|
|
12
14
|
|
|
13
15
|
static propTypes = {
|
|
@@ -16,7 +18,7 @@ class Spin extends PureComponent {
|
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
static defaultProps = {
|
|
19
|
-
size:
|
|
21
|
+
size: SMALL,
|
|
20
22
|
color: '#999',
|
|
21
23
|
}
|
|
22
24
|
|
|
@@ -27,10 +29,22 @@ class Spin extends PureComponent {
|
|
|
27
29
|
color,
|
|
28
30
|
} = this.props
|
|
29
31
|
|
|
32
|
+
// 尺寸和 ios 保持一致
|
|
33
|
+
let width = 20
|
|
34
|
+
let height = 20
|
|
35
|
+
if (size !== SMALL) {
|
|
36
|
+
width = height = 36
|
|
37
|
+
}
|
|
38
|
+
|
|
30
39
|
return (
|
|
31
40
|
<RNTSpin
|
|
32
|
-
size={size === 'small' ? 10 : 20}
|
|
33
41
|
color={color}
|
|
42
|
+
style={{
|
|
43
|
+
width,
|
|
44
|
+
height,
|
|
45
|
+
// ios 是居中的表现
|
|
46
|
+
alignSelf: 'center',
|
|
47
|
+
}}
|
|
34
48
|
/>
|
|
35
49
|
)
|
|
36
50
|
|
package/js/Spin.ios.js
CHANGED
|
@@ -3,11 +3,14 @@ import React, {
|
|
|
3
3
|
} from 'react'
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
+
View,
|
|
6
7
|
ActivityIndicator,
|
|
7
8
|
} from 'react-native'
|
|
8
9
|
|
|
9
10
|
import PropTypes from 'prop-types'
|
|
10
11
|
|
|
12
|
+
import { SMALL } from './size'
|
|
13
|
+
|
|
11
14
|
export default class Spin extends PureComponent {
|
|
12
15
|
|
|
13
16
|
static propTypes = {
|
|
@@ -16,7 +19,7 @@ export default class Spin extends PureComponent {
|
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
static defaultProps = {
|
|
19
|
-
size:
|
|
22
|
+
size: SMALL,
|
|
20
23
|
color: '#999',
|
|
21
24
|
}
|
|
22
25
|
|
|
@@ -36,4 +39,4 @@ export default class Spin extends PureComponent {
|
|
|
36
39
|
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
}
|
|
42
|
+
}
|
package/js/size.js
ADDED
package/package.json
CHANGED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
package com.github.reactnativehero.spin
|
|
2
|
-
|
|
3
|
-
import android.graphics.Color
|
|
4
|
-
import android.view.View
|
|
5
|
-
import com.facebook.react.uimanager.ThemedReactContext
|
|
6
|
-
|
|
7
|
-
class SpinView(private val reactContext: ThemedReactContext) : View(reactContext) {
|
|
8
|
-
|
|
9
|
-
var size = 0
|
|
10
|
-
|
|
11
|
-
set(value) {
|
|
12
|
-
if (field == value) {
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
field = value
|
|
16
|
-
applySpin()
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
var color = Color.TRANSPARENT
|
|
20
|
-
|
|
21
|
-
set(value) {
|
|
22
|
-
if (field == value) {
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
field = value
|
|
26
|
-
applySpin()
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private fun applySpin() {
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
}
|