├── .gitignore
├── .npmignore
├── AnyHeader.js
├── ClassicsHeader.js
├── DefaultHeader.js
├── Example
├── .babelrc
├── .buckconfig
├── .flowconfig
├── .gitattributes
├── .gitignore
├── .watchmanconfig
├── App.js
├── FlatListExample.js
├── HuaWeiRefreshControl.js
├── ListViewExample.js
├── ListViewExample1.js
├── LottieListViewExample.js
├── LottieRefreshControl.js
├── android
│ ├── app
│ │ ├── BUCK
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── assets
│ │ │ └── fonts
│ │ │ │ ├── Entypo.ttf
│ │ │ │ ├── EvilIcons.ttf
│ │ │ │ ├── Feather.ttf
│ │ │ │ ├── FontAwesome.ttf
│ │ │ │ ├── Foundation.ttf
│ │ │ │ ├── Ionicons.ttf
│ │ │ │ ├── MaterialCommunityIcons.ttf
│ │ │ │ ├── MaterialIcons.ttf
│ │ │ │ ├── Octicons.ttf
│ │ │ │ ├── SimpleLineIcons.ttf
│ │ │ │ └── Zocial.ttf
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── MainApplication.java
│ │ │ └── res
│ │ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ │ └── values
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── keystores
│ │ ├── BUCK
│ │ └── debug.keystore.properties
│ └── settings.gradle
├── app.json
├── cycle_animation.json
├── index.js
├── ios
│ ├── Example-tvOS
│ │ └── Info.plist
│ ├── Example-tvOSTests
│ │ └── Info.plist
│ ├── Example.xcodeproj
│ │ ├── project.pbxproj
│ │ └── xcshareddata
│ │ │ └── xcschemes
│ │ │ ├── Example-tvOS.xcscheme
│ │ │ └── Example.xcscheme
│ ├── Example
│ │ ├── AppDelegate.h
│ │ ├── AppDelegate.m
│ │ ├── Base.lproj
│ │ │ └── LaunchScreen.xib
│ │ ├── Images.xcassets
│ │ │ ├── AppIcon.appiconset
│ │ │ │ └── Contents.json
│ │ │ └── Contents.json
│ │ ├── Info.plist
│ │ └── main.m
│ └── ExampleTests
│ │ ├── ExampleTests.m
│ │ └── Info.plist
├── loading.json
├── loop.json
├── package.json
├── untitled.gif
└── yarn.lock
├── LICENSE
├── MaterialHeader.js
├── README.md
├── SmartRefreshControl.js
├── StoreHouseHeader.js
├── Util.js
├── android
├── .gitignore
├── build.gradle
├── proguard-rules.pro
├── smartrefreshlayout.iml
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── lmy
│ │ └── smartrefreshlayout
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── lmy
│ │ │ ├── header
│ │ │ ├── AnyHeader.java
│ │ │ ├── AnyHeaderManager.java
│ │ │ ├── ClassicsHeaderManager.java
│ │ │ ├── DefaultHeader.java
│ │ │ ├── DefaultHeaderMananger.java
│ │ │ ├── MaterialHeaderManager.java
│ │ │ └── StoreHouseHeaderManager.java
│ │ │ └── smartrefreshlayout
│ │ │ ├── Events.java
│ │ │ ├── HeaderType.java
│ │ │ ├── RCTSpinnerStyleModule.java
│ │ │ ├── ReactSmartRefreshLayout.java
│ │ │ ├── SmartRefreshLayoutManager.java
│ │ │ ├── SmartRefreshLayoutPackage.java
│ │ │ └── SpinnerStyleConstants.java
│ └── res
│ │ └── values
│ │ ├── ids.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── lmy
│ └── smartrefreshlayout
│ └── ExampleUnitTest.java
├── docs
├── AnyHeader.md
├── DefaultHeader.md
└── StoreHouse.md
├── images
├── Screenshot_1520489593.png
├── Screenshot_1520489605.png
└── lottierefresh.gif
├── index.d.ts
├── index.js
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | .DS_Store
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .idea
2 | Example
3 | images
4 | docs
--------------------------------------------------------------------------------
/AnyHeader.js:
--------------------------------------------------------------------------------
1 | import React, {Component} from 'react';
2 | import {
3 | StyleSheet,
4 | View,
5 | Text,
6 | requireNativeComponent,
7 | findNodeHandle,
8 | UIManager,
9 | } from 'react-native';
10 | import PropTypes from 'prop-types';
11 | import {ViewPropTypes} from './Util'
12 |
13 | const RCTAnyHeader = requireNativeComponent('RCTAnyHeader', RCTAnyHeader);
14 |
15 | class AnyHeader extends Component {
16 |
17 | render() {
18 | return (
19 |
22 |
23 | )
24 | }
25 | }
26 |
27 | AnyHeader.propTypes = {
28 | primaryColor:PropTypes.string,
29 | ...ViewPropTypes,
30 | }
31 | export default AnyHeader;
--------------------------------------------------------------------------------
/ClassicsHeader.js:
--------------------------------------------------------------------------------
1 | import React, {Component} from 'react';
2 | import {requireNativeComponent} from 'react-native';
3 | import {ViewPropTypes} from './Util';
4 | import PropTypes from 'prop-types';
5 |
6 | const RCTClassicsHeader = requireNativeComponent('RCTClassicsHeader', RCTClassicsHeader);
7 |
8 | export default class ClassicsHeader extends Component {
9 | static propTypes = {
10 | primaryColor: PropTypes.string,
11 | accentColor: PropTypes.string,
12 | ...ViewPropTypes,
13 | }
14 |
15 | render() {
16 | return ()
17 | }
18 | }
--------------------------------------------------------------------------------
/DefaultHeader.js:
--------------------------------------------------------------------------------
1 | import React, {Component} from 'react';
2 | import {requireNativeComponent} from 'react-native';
3 | import {ViewPropTypes} from './Util';
4 | import PropTypes from 'prop-types';
5 |
6 | const RCTDefaultHeader = requireNativeComponent('RCTDefaultHeader', RCTDefaultHeader);
7 |
8 | export default class DefaultHeader extends Component {
9 | static propTypes = {
10 | primaryColor: PropTypes.string,
11 | accentColor: PropTypes.string,
12 | ...ViewPropTypes,
13 | }
14 |
15 | render() {
16 | return ()
17 | }
18 | }
--------------------------------------------------------------------------------
/Example/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["react-native"]
3 | }
4 |
--------------------------------------------------------------------------------
/Example/.buckconfig:
--------------------------------------------------------------------------------
1 |
2 | [android]
3 | target = Google Inc.:Google APIs:23
4 |
5 | [maven_repositories]
6 | central = https://repo1.maven.org/maven2
7 |
--------------------------------------------------------------------------------
/Example/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 | ; We fork some components by platform
3 | .*/*[.]android.js
4 |
5 | ; Ignore "BUCK" generated dirs
6 | /\.buckd/
7 |
8 | ; Ignore unexpected extra "@providesModule"
9 | .*/node_modules/.*/node_modules/fbjs/.*
10 |
11 | ; Ignore duplicate module providers
12 | ; For RN Apps installed via npm, "Libraries" folder is inside
13 | ; "node_modules/react-native" but in the source repo it is in the root
14 | .*/Libraries/react-native/React.js
15 |
16 | ; Ignore polyfills
17 | .*/Libraries/polyfills/.*
18 |
19 | ; Ignore metro
20 | .*/node_modules/metro/.*
21 |
22 | [include]
23 |
24 | [libs]
25 | node_modules/react-native/Libraries/react-native/react-native-interface.js
26 | node_modules/react-native/flow/
27 | node_modules/react-native/flow-github/
28 |
29 | [options]
30 | emoji=true
31 |
32 | module.system=haste
33 |
34 | munge_underscores=true
35 |
36 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
37 |
38 | module.file_ext=.js
39 | module.file_ext=.jsx
40 | module.file_ext=.json
41 | module.file_ext=.native.js
42 |
43 | suppress_type=$FlowIssue
44 | suppress_type=$FlowFixMe
45 | suppress_type=$FlowFixMeProps
46 | suppress_type=$FlowFixMeState
47 |
48 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
49 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
50 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
51 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
52 |
53 | [version]
54 | ^0.67.0
55 |
--------------------------------------------------------------------------------
/Example/.gitattributes:
--------------------------------------------------------------------------------
1 | *.pbxproj -text
2 |
--------------------------------------------------------------------------------
/Example/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # Xcode
6 | #
7 | build/
8 | *.pbxuser
9 | !default.pbxuser
10 | *.mode1v3
11 | !default.mode1v3
12 | *.mode2v3
13 | !default.mode2v3
14 | *.perspectivev3
15 | !default.perspectivev3
16 | xcuserdata
17 | *.xccheckout
18 | *.moved-aside
19 | DerivedData
20 | *.hmap
21 | *.ipa
22 | *.xcuserstate
23 | project.xcworkspace
24 |
25 | # Android/IntelliJ
26 | #
27 | build/
28 | .idea
29 | .gradle
30 | local.properties
31 | *.iml
32 |
33 | # node.js
34 | #
35 | node_modules/
36 | npm-debug.log
37 | yarn-error.log
38 |
39 | # BUCK
40 | buck-out/
41 | \.buckd/
42 | *.keystore
43 |
44 | # fastlane
45 | #
46 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
47 | # screenshots whenever they are needed.
48 | # For more information about the recommended setup visit:
49 | # https://docs.fastlane.tools/best-practices/source-control/
50 |
51 | */fastlane/report.xml
52 | */fastlane/Preview.html
53 | */fastlane/screenshots
54 |
55 | # Bundle artifact
56 | *.jsbundle
57 |
--------------------------------------------------------------------------------
/Example/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/Example/App.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Sample React Native App
3 | * https://github.com/facebook/react-native
4 | * @flow
5 | */
6 |
7 | import React, {Component} from 'react';
8 | import {
9 | Platform,
10 | StyleSheet,
11 | Text,
12 | View,
13 | ScrollView,
14 | Animated,
15 | Easing
16 | } from 'react-native';
17 | import HuaWeiRefreshControl from './HuaWeiRefreshControl'
18 | import ListViewExample from './ListViewExample'
19 | import FlatListExample from "./FlatListExample";
20 | import ListViewExample1 from './ListViewExample1'
21 | const instructions = Platform.select({
22 | ios: 'Press Cmd+R to reload,\n' +
23 | 'Cmd+D or shake for dev menu',
24 | android: 'Double tap R on your keyboard to reload,\n' +
25 | 'Shake or press menu button for dev menu',
26 | });
27 | Date.prototype.Format = function (fmt) { // author: meizz
28 | var o = {
29 | "M+": this.getMonth() + 1, // 月份
30 | "d+": this.getDate(), // 日
31 | "h+": this.getHours(), // 小时
32 | "m+": this.getMinutes(), // 分
33 | "s+": this.getSeconds(), // 秒
34 | "q+": Math.floor((this.getMonth() + 3) / 3), // 季度
35 | "S": this.getMilliseconds() // 毫秒
36 | };
37 | if (/(y+)/.test(fmt))
38 | fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
39 | for (var k in o)
40 | if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
41 | return fmt;
42 | }
43 | type Props = {};
44 | export default class App extends Component {
45 | render() {
46 | return (
47 |
48 | );
49 | }
50 | }
51 |
52 | const styles = StyleSheet.create({
53 | container: {
54 | flex: 1,
55 | justifyContent: 'center',
56 | alignItems: 'center',
57 | backgroundColor: '#F5FCFF',
58 | height:1000
59 | },
60 | welcome: {
61 | fontSize: 20,
62 | textAlign: 'center',
63 | margin: 10,
64 | },
65 | instructions: {
66 | textAlign: 'center',
67 | color: '#333333',
68 | marginBottom: 5,
69 | },
70 | });
71 |
--------------------------------------------------------------------------------
/Example/FlatListExample.js:
--------------------------------------------------------------------------------
1 | import React, {Component} from 'react';
2 | import {StyleSheet, View, Text,ListView,ScrollView,FlatList} from 'react-native';
3 | import PropTypes from 'prop-types';
4 | import HuaWeiRefreshControl from './HuaWeiRefreshControl';
5 |
6 | export default class FlatListExample extends Component {
7 | constructor(props){
8 | super(props);
9 | this.state = {
10 | data: ['row 1', 'row 2','row 3','row 4','row 5','row 6','row 7','row 8'],
11 | };
12 | }
13 | _onRefresh=()=>{
14 | setTimeout(()=>{
15 | this._hw && this._hw.finishRefresh()
16 | },1000)
17 | }
18 | render() {
19 | return (
20 |
21 | item}
23 | data={this.state.data}
24 | renderItem={({item,index}) => alert(111)} style={{height:100}}>{item}}
25 | renderScrollComponent={props=>this._hw = ref}
30 | onRefresh={this._onRefresh}
31 | />
32 | }
33 | {...props}
34 | />}
35 | />
36 |
37 | )
38 | }
39 | }
--------------------------------------------------------------------------------
/Example/HuaWeiRefreshControl.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 类似华为手机的下拉刷新
3 | */
4 | import React, {Component} from 'react';
5 | import {
6 | StyleSheet,
7 | View,
8 | Text,
9 | Animated,
10 | Easing
11 | } from 'react-native';
12 | import PropTypes from 'prop-types';
13 | import {SmartRefreshControl, AnyHeader} from 'react-native-smartrefreshlayout';
14 | import Icon from 'react-native-vector-icons/Ionicons';
15 | import {SkypeIndicator} from 'react-native-indicators';
16 |
17 | const AnimatedIcon = Animated.createAnimatedComponent(Icon);
18 | export default class HuaWeiRefreshControl extends Component {
19 | state = {
20 | text: '下拉刷新',
21 | rotate: new Animated.Value(0),
22 | refreshing: false
23 | }
24 | _onPullDownToRefresh = () => {
25 | this.setState({
26 | text: '下拉刷新',
27 | refreshing: false
28 | })
29 | Animated.timing(this.state.rotate, {
30 | toValue: 0,
31 | duration: 197,
32 | useNativeDriver: true,
33 | easing: Easing.linear()
34 | }).start()
35 | }
36 | _onReleased = () => {
37 | this.setState({
38 | refreshing: true,
39 | text: '正在刷新'
40 | });
41 | }
42 | _onReleaseToRefresh = () => {
43 | this.setState({
44 | text: '释放刷新'
45 | })
46 | Animated.timing(this.state.rotate, {
47 | toValue: 1,
48 | duration: 197,
49 | useNativeDriver: true,
50 | easing: Easing.linear()
51 | }).start()
52 | }
53 | _onRefresh = () => {
54 | let {onRefresh} = this.props;
55 | onRefresh && onRefresh();
56 | }
57 | finishRefresh=(params)=>{
58 | this._refreshc && this._refreshc.finishRefresh(params)
59 | }
60 | render() {
61 | return (
62 | this._refreshc = ref}
65 | children={this.props.children}
66 | onRefresh={this._onRefresh}
67 | onPullDownToRefresh={this._onPullDownToRefresh}
68 | onHeaderReleased={this._onReleased}
69 | onReleaseToRefresh={this._onReleaseToRefresh}
70 | headerHeight={100}
71 | HeaderComponent={
72 |
78 | {this.state.refreshing ? :
79 | }
87 | {this.state.text}
88 |
89 | }
90 | />
91 | )
92 | }
93 | }
--------------------------------------------------------------------------------
/Example/ListViewExample.js:
--------------------------------------------------------------------------------
1 | import React, {Component} from 'react';
2 | import {StyleSheet, View, Text,ListView,ScrollView} from 'react-native';
3 | import PropTypes from 'prop-types';
4 | import HuaWeiRefreshControl from './HuaWeiRefreshControl';
5 |
6 | export default class ListViewExample extends Component {
7 | constructor(props){
8 | super(props);
9 | var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
10 | this.state = {
11 | dataSource: ds.cloneWithRows(['row 1', 'row 2','row 3','row 4','row 5','row 6','row 7','row 8']),
12 | };
13 | }
14 | _onRefresh=()=>{
15 | setTimeout(()=>{
16 | this._hw && this._hw.finishRefresh()
17 | },1000)
18 | }
19 | render() {
20 | return (
21 |
22 | alert(111)} style={{height:100}}>{rowData}}
25 | renderScrollComponent={props=>this._hw = ref}
30 | onRefresh={this._onRefresh}
31 | />
32 | }
33 | {...props}
34 | />}
35 | />
36 |
37 | )
38 | }
39 | }
--------------------------------------------------------------------------------
/Example/ListViewExample1.js:
--------------------------------------------------------------------------------
1 | import React, {Component} from 'react';
2 | import {StyleSheet, View, Text,ListView,ScrollView,ViewPagerAndroid} from 'react-native';
3 | import PropTypes from 'prop-types';
4 | import HuaWeiRefreshControl from './HuaWeiRefreshControl';
5 |
6 | export default class ListViewExample1 extends Component {
7 | constructor(props){
8 | super(props);
9 | var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
10 | this.state = {
11 | dataSource: ds.cloneWithRows(['row 1', 'row 2','row 3','row 4','row 5','row 6','row 7','row 8']),
12 | };
13 | }
14 | _onRefresh=()=>{
15 | setTimeout(()=>{
16 | this._hw && this._hw.finishRefresh()
17 | },1000)
18 | }
19 | render() {
20 | return (
21 |
22 |
26 |
27 | First page
28 |
29 |
30 | Second page
31 |
32 | }
33 | refreshControl={this._hw = ref}
35 | onRefresh={this._onRefresh}
36 | />}
37 | dataSource={this.state.dataSource}
38 | renderRow={(rowData) => alert(111)} style={{height:100,borderColor:'black',borderWidth:1}}>{rowData}}
39 | />
40 |
41 | )
42 | }
43 | }
44 | const styles = StyleSheet.create({
45 | viewPager: {
46 | flex: 1,
47 | height:300
48 | },
49 | pageStyle: {
50 | alignItems: 'center',
51 | padding: 20,
52 | }
53 | })
--------------------------------------------------------------------------------
/Example/LottieListViewExample.js:
--------------------------------------------------------------------------------
1 | import React, {Component} from 'react';
2 | import {StyleSheet, View, Text,ListView,ScrollView} from 'react-native';
3 | import PropTypes from 'prop-types';
4 | import HuaWeiRefreshControl from './HuaWeiRefreshControl';
5 | import LottieRefreshControl from "./LottieRefreshControl";
6 |
7 | export default class LottieListViewExample extends Component {
8 | constructor(props){
9 | super(props);
10 | var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
11 | this.state = {
12 | dataSource: ds.cloneWithRows(['row 1', 'row 2','row 3','row 4','row 5','row 6','row 7','row 8']),
13 | };
14 | }
15 | _onRefresh=()=>{
16 | setTimeout(()=>{
17 | this._hw && this._hw.finishRefresh()
18 | },1000)
19 | }
20 | render() {
21 | return (
22 |
23 | alert(111)} style={{height:100}}>{rowData}}
26 | renderScrollComponent={props=>this._hw = ref}
31 | onRefresh={this._onRefresh}
32 | />
33 | }
34 | {...props}
35 | />}
36 | />
37 |
38 | )
39 | }
40 | }
--------------------------------------------------------------------------------
/Example/LottieRefreshControl.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 类似华为手机的下拉刷新
3 | */
4 | import React, {Component} from 'react';
5 | import {
6 | StyleSheet,
7 | View,
8 | Text,
9 | Animated,
10 | Easing
11 | } from 'react-native';
12 | import PropTypes from 'prop-types';
13 | import LottieView from 'lottie-react-native'
14 | import {SmartRefreshControl, AnyHeader} from 'react-native-smartrefreshlayout';
15 |
16 | export default class LottieRefreshControl extends Component {
17 | state = {
18 | scale: new Animated.Value(0.1)
19 | }
20 | _onRefresh = () => {
21 | let {onRefresh} = this.props;
22 | onRefresh && onRefresh();
23 | this.lottieView.play(this.state.scale.__getValue())
24 |
25 | }
26 | finishRefresh=(params)=>{
27 | this._refreshc && this._refreshc.finishRefresh(params);
28 | this.lottieView.reset();
29 | }
30 | _onHeaderMoving=(event)=>{
31 | let {percent} = event.nativeEvent;
32 | if(percent<=1) {
33 | this.state.scale.setValue(event.nativeEvent.percent);
34 | }
35 | }
36 | render() {
37 | return (
38 | this._refreshc = ref}
42 | children={this.props.children}
43 | onRefresh={this._onRefresh}
44 | headerHeight={100}
45 | HeaderComponent={
46 |
47 |
53 | this.lottieView = obj} style={{width:100,height:100}} hardwareAccelerationAndroid progress={this.state.scale} source={require('./cycle_animation.json')} />
54 |
55 |
56 | }
57 | />
58 | )
59 | }
60 | }
--------------------------------------------------------------------------------
/Example/android/app/BUCK:
--------------------------------------------------------------------------------
1 | # To learn about Buck see [Docs](https://buckbuild.com/).
2 | # To run your application with Buck:
3 | # - install Buck
4 | # - `npm start` - to start the packager
5 | # - `cd android`
6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
8 | # - `buck install -r android/app` - compile, install and run application
9 | #
10 |
11 | lib_deps = []
12 |
13 | for jarfile in glob(['libs/*.jar']):
14 | name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')]
15 | lib_deps.append(':' + name)
16 | prebuilt_jar(
17 | name = name,
18 | binary_jar = jarfile,
19 | )
20 |
21 | for aarfile in glob(['libs/*.aar']):
22 | name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')]
23 | lib_deps.append(':' + name)
24 | android_prebuilt_aar(
25 | name = name,
26 | aar = aarfile,
27 | )
28 |
29 | android_library(
30 | name = "all-libs",
31 | exported_deps = lib_deps,
32 | )
33 |
34 | android_library(
35 | name = "app-code",
36 | srcs = glob([
37 | "src/main/java/**/*.java",
38 | ]),
39 | deps = [
40 | ":all-libs",
41 | ":build_config",
42 | ":res",
43 | ],
44 | )
45 |
46 | android_build_config(
47 | name = "build_config",
48 | package = "com.example",
49 | )
50 |
51 | android_resource(
52 | name = "res",
53 | package = "com.example",
54 | res = "src/main/res",
55 | )
56 |
57 | android_binary(
58 | name = "app",
59 | keystore = "//android/keystores:debug",
60 | manifest = "src/main/AndroidManifest.xml",
61 | package_type = "debug",
62 | deps = [
63 | ":app-code",
64 | ],
65 | )
66 |
--------------------------------------------------------------------------------
/Example/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "com.android.application"
2 |
3 | import com.android.build.OutputFile
4 |
5 | /**
6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
7 | * and bundleReleaseJsAndAssets).
8 | * These basically call `react-native bundle` with the correct arguments during the Android build
9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
10 | * bundle directly from the development server. Below you can see all the possible configurations
11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the
12 | * `apply from: "../../node_modules/react-native/react.gradle"` line.
13 | *
14 | * project.ext.react = [
15 | * // the name of the generated asset file containing your JS bundle
16 | * bundleAssetName: "index.android.bundle",
17 | *
18 | * // the entry file for bundle generation
19 | * entryFile: "index.android.js",
20 | *
21 | * // whether to bundle JS and assets in debug mode
22 | * bundleInDebug: false,
23 | *
24 | * // whether to bundle JS and assets in release mode
25 | * bundleInRelease: true,
26 | *
27 | * // whether to bundle JS and assets in another build variant (if configured).
28 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
29 | * // The configuration property can be in the following formats
30 | * // 'bundleIn${productFlavor}${buildType}'
31 | * // 'bundleIn${buildType}'
32 | * // bundleInFreeDebug: true,
33 | * // bundleInPaidRelease: true,
34 | * // bundleInBeta: true,
35 | *
36 | * // whether to disable dev mode in custom build variants (by default only disabled in release)
37 | * // for example: to disable dev mode in the staging build type (if configured)
38 | * devDisabledInStaging: true,
39 | * // The configuration property can be in the following formats
40 | * // 'devDisabledIn${productFlavor}${buildType}'
41 | * // 'devDisabledIn${buildType}'
42 | *
43 | * // the root of your project, i.e. where "package.json" lives
44 | * root: "../../",
45 | *
46 | * // where to put the JS bundle asset in debug mode
47 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
48 | *
49 | * // where to put the JS bundle asset in release mode
50 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release",
51 | *
52 | * // where to put drawable resources / React Native assets, e.g. the ones you use via
53 | * // require('./image.png')), in debug mode
54 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
55 | *
56 | * // where to put drawable resources / React Native assets, e.g. the ones you use via
57 | * // require('./image.png')), in release mode
58 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
59 | *
60 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means
61 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
62 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle
63 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
64 | * // for example, you might want to remove it from here.
65 | * inputExcludes: ["android/**", "ios/**"],
66 | *
67 | * // override which node gets called and with what additional arguments
68 | * nodeExecutableAndArgs: ["node"],
69 | *
70 | * // supply additional arguments to the packager
71 | * extraPackagerArgs: []
72 | * ]
73 | */
74 |
75 | project.ext.react = [
76 | entryFile: "index.js"
77 | ]
78 |
79 | apply from: "../../node_modules/react-native/react.gradle"
80 |
81 | /**
82 | * Set this to true to create two separate APKs instead of one:
83 | * - An APK that only works on ARM devices
84 | * - An APK that only works on x86 devices
85 | * The advantage is the size of the APK is reduced by about 4MB.
86 | * Upload all the APKs to the Play Store and people will download
87 | * the correct one based on the CPU architecture of their device.
88 | */
89 | def enableSeparateBuildPerCPUArchitecture = false
90 |
91 | /**
92 | * Run Proguard to shrink the Java bytecode in release builds.
93 | */
94 | def enableProguardInReleaseBuilds = false
95 |
96 | android {
97 | compileSdkVersion 26
98 | buildToolsVersion "23.0.1"
99 |
100 | defaultConfig {
101 | applicationId "com.example"
102 | minSdkVersion 16
103 | targetSdkVersion 22
104 | versionCode 1
105 | versionName "1.0"
106 | ndk {
107 | abiFilters "armeabi-v7a", "x86"
108 | }
109 | }
110 | splits {
111 | abi {
112 | reset()
113 | enable enableSeparateBuildPerCPUArchitecture
114 | universalApk false // If true, also generate a universal APK
115 | include "armeabi-v7a", "x86"
116 | }
117 | }
118 | buildTypes {
119 | release {
120 | minifyEnabled enableProguardInReleaseBuilds
121 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
122 | }
123 | }
124 | // applicationVariants are e.g. debug, release
125 | applicationVariants.all { variant ->
126 | variant.outputs.each { output ->
127 | // For each separate APK per architecture, set a unique version code as described here:
128 | // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
129 | def versionCodes = ["armeabi-v7a":1, "x86":2]
130 | def abi = output.getFilter(OutputFile.ABI)
131 | if (abi != null) { // null for the universal-debug, universal-release variants
132 | output.versionCodeOverride =
133 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
134 | }
135 | }
136 | }
137 | }
138 |
139 | dependencies {
140 | compile project(':lottie-react-native')
141 | compile project(':react-native-smartrefreshlayout')
142 | compile project(':react-native-vector-icons')
143 | compile fileTree(dir: "libs", include: ["*.jar"])
144 | compile "com.android.support:appcompat-v7:23.0.1"
145 | compile "com.facebook.react:react-native:+" // From node_modules
146 | }
147 |
148 | // Run this once to be able to run the application with BUCK
149 | // puts all compile dependencies into folder libs for BUCK to use
150 | task copyDownloadableDepsToLibs(type: Copy) {
151 | from configurations.compile
152 | into 'libs'
153 | }
154 |
--------------------------------------------------------------------------------
/Example/android/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Disabling obfuscation is useful if you collect stack traces from production crashes
20 | # (unless you are using a system that supports de-obfuscate the stack traces).
21 | -dontobfuscate
22 |
23 | # React Native
24 |
25 | # Keep our interfaces so they can be used by other ProGuard rules.
26 | # See http://sourceforge.net/p/proguard/bugs/466/
27 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
28 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
29 | -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
30 |
31 | # Do not strip any method/class that is annotated with @DoNotStrip
32 | -keep @com.facebook.proguard.annotations.DoNotStrip class *
33 | -keep @com.facebook.common.internal.DoNotStrip class *
34 | -keepclassmembers class * {
35 | @com.facebook.proguard.annotations.DoNotStrip *;
36 | @com.facebook.common.internal.DoNotStrip *;
37 | }
38 |
39 | -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
40 | void set*(***);
41 | *** get*();
42 | }
43 |
44 | -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
45 | -keep class * extends com.facebook.react.bridge.NativeModule { *; }
46 | -keepclassmembers,includedescriptorclasses class * { native ; }
47 | -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; }
48 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; }
49 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; }
50 |
51 | -dontwarn com.facebook.react.**
52 |
53 | # TextLayoutBuilder uses a non-public Android constructor within StaticLayout.
54 | # See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details.
55 | -dontwarn android.text.StaticLayout
56 |
57 | # okhttp
58 |
59 | -keepattributes Signature
60 | -keepattributes *Annotation*
61 | -keep class okhttp3.** { *; }
62 | -keep interface okhttp3.** { *; }
63 | -dontwarn okhttp3.**
64 |
65 | # okio
66 |
67 | -keep class sun.misc.Unsafe { *; }
68 | -dontwarn java.nio.file.*
69 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
70 | -dontwarn okio.**
71 |
--------------------------------------------------------------------------------
/Example/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
13 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Example/android/app/src/main/assets/fonts/Entypo.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/android/app/src/main/assets/fonts/Entypo.ttf
--------------------------------------------------------------------------------
/Example/android/app/src/main/assets/fonts/EvilIcons.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/android/app/src/main/assets/fonts/EvilIcons.ttf
--------------------------------------------------------------------------------
/Example/android/app/src/main/assets/fonts/Feather.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/android/app/src/main/assets/fonts/Feather.ttf
--------------------------------------------------------------------------------
/Example/android/app/src/main/assets/fonts/FontAwesome.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/android/app/src/main/assets/fonts/FontAwesome.ttf
--------------------------------------------------------------------------------
/Example/android/app/src/main/assets/fonts/Foundation.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/android/app/src/main/assets/fonts/Foundation.ttf
--------------------------------------------------------------------------------
/Example/android/app/src/main/assets/fonts/Ionicons.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/android/app/src/main/assets/fonts/Ionicons.ttf
--------------------------------------------------------------------------------
/Example/android/app/src/main/assets/fonts/MaterialCommunityIcons.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/android/app/src/main/assets/fonts/MaterialCommunityIcons.ttf
--------------------------------------------------------------------------------
/Example/android/app/src/main/assets/fonts/MaterialIcons.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/android/app/src/main/assets/fonts/MaterialIcons.ttf
--------------------------------------------------------------------------------
/Example/android/app/src/main/assets/fonts/Octicons.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/android/app/src/main/assets/fonts/Octicons.ttf
--------------------------------------------------------------------------------
/Example/android/app/src/main/assets/fonts/SimpleLineIcons.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/android/app/src/main/assets/fonts/SimpleLineIcons.ttf
--------------------------------------------------------------------------------
/Example/android/app/src/main/assets/fonts/Zocial.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/android/app/src/main/assets/fonts/Zocial.ttf
--------------------------------------------------------------------------------
/Example/android/app/src/main/java/com/example/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import com.facebook.react.ReactActivity;
4 |
5 | public class MainActivity extends ReactActivity {
6 |
7 | /**
8 | * Returns the name of the main component registered from JavaScript.
9 | * This is used to schedule rendering of the component.
10 | */
11 | @Override
12 | protected String getMainComponentName() {
13 | return "Example";
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Example/android/app/src/main/java/com/example/MainApplication.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import android.app.Application;
4 |
5 | import com.facebook.react.ReactApplication;
6 | import com.airbnb.android.react.lottie.LottiePackage;
7 | import com.lmy.smartrefreshlayout.SmartRefreshLayoutPackage;
8 | import com.oblador.vectoricons.VectorIconsPackage;
9 | import com.facebook.react.ReactNativeHost;
10 | import com.facebook.react.ReactPackage;
11 | import com.facebook.react.shell.MainReactPackage;
12 | import com.facebook.soloader.SoLoader;
13 |
14 | import java.util.Arrays;
15 | import java.util.List;
16 |
17 | public class MainApplication extends Application implements ReactApplication {
18 |
19 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
20 | @Override
21 | public boolean getUseDeveloperSupport() {
22 | return BuildConfig.DEBUG;
23 | }
24 |
25 | @Override
26 | protected List getPackages() {
27 | return Arrays.asList(
28 | new MainReactPackage(),
29 | new LottiePackage(),
30 | new SmartRefreshLayoutPackage(),
31 | new VectorIconsPackage() );
32 | }
33 |
34 | @Override
35 | protected String getJSMainModuleName() {
36 | return "index";
37 | }
38 | };
39 |
40 | @Override
41 | public ReactNativeHost getReactNativeHost() {
42 | return mReactNativeHost;
43 | }
44 |
45 | @Override
46 | public void onCreate() {
47 | super.onCreate();
48 | SoLoader.init(this, /* native exopackage */ false);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Example/android/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Example
3 |
4 |
--------------------------------------------------------------------------------
/Example/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Example/android/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 |
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:2.2.3'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | mavenLocal()
19 | jcenter()
20 | maven {
21 | url 'https://maven.google.com'
22 | }
23 | maven {
24 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
25 | url "$rootDir/../node_modules/react-native/android"
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Example/android/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | android.useDeprecatedNdk=true
21 |
--------------------------------------------------------------------------------
/Example/android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Example/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | zipStoreBase=GRADLE_USER_HOME
4 | zipStorePath=wrapper/dists
5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
6 |
--------------------------------------------------------------------------------
/Example/android/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/Example/android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/Example/android/keystores/BUCK:
--------------------------------------------------------------------------------
1 | keystore(
2 | name = "debug",
3 | properties = "debug.keystore.properties",
4 | store = "debug.keystore",
5 | visibility = [
6 | "PUBLIC",
7 | ],
8 | )
9 |
--------------------------------------------------------------------------------
/Example/android/keystores/debug.keystore.properties:
--------------------------------------------------------------------------------
1 | key.store=debug.keystore
2 | key.alias=androiddebugkey
3 | key.store.password=android
4 | key.alias.password=android
5 |
--------------------------------------------------------------------------------
/Example/android/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'Example'
2 | include ':lottie-react-native'
3 | project(':lottie-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/lottie-react-native/src/android')
4 | include ':react-native-smartrefreshlayout'
5 | project(':react-native-smartrefreshlayout').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-smartrefreshlayout/android')
6 | include ':react-native-vector-icons'
7 | project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
8 | include ':app'
9 |
--------------------------------------------------------------------------------
/Example/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Example",
3 | "displayName": "Example"
4 | }
--------------------------------------------------------------------------------
/Example/index.js:
--------------------------------------------------------------------------------
1 | import { AppRegistry } from 'react-native';
2 | import App from './App';
3 |
4 | AppRegistry.registerComponent('Example', () => App);
5 |
--------------------------------------------------------------------------------
/Example/ios/Example-tvOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UIViewControllerBasedStatusBarAppearance
38 |
39 | NSLocationWhenInUseUsageDescription
40 |
41 | NSAppTransportSecurity
42 |
43 |
44 | NSExceptionDomains
45 |
46 | localhost
47 |
48 | NSExceptionAllowsInsecureHTTPLoads
49 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/Example/ios/Example-tvOSTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example-tvOS.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
43 |
49 |
50 |
51 |
52 |
53 |
58 |
59 |
61 |
67 |
68 |
69 |
70 |
71 |
77 |
78 |
79 |
80 |
81 |
82 |
92 |
94 |
100 |
101 |
102 |
103 |
104 |
105 |
111 |
113 |
119 |
120 |
121 |
122 |
124 |
125 |
128 |
129 |
130 |
--------------------------------------------------------------------------------
/Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
43 |
49 |
50 |
51 |
52 |
53 |
58 |
59 |
61 |
67 |
68 |
69 |
70 |
71 |
77 |
78 |
79 |
80 |
81 |
82 |
92 |
94 |
100 |
101 |
102 |
103 |
104 |
105 |
111 |
113 |
119 |
120 |
121 |
122 |
124 |
125 |
128 |
129 |
130 |
--------------------------------------------------------------------------------
/Example/ios/Example/AppDelegate.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015-present, Facebook, Inc.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | #import
9 |
10 | @interface AppDelegate : UIResponder
11 |
12 | @property (nonatomic, strong) UIWindow *window;
13 |
14 | @end
15 |
--------------------------------------------------------------------------------
/Example/ios/Example/AppDelegate.m:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015-present, Facebook, Inc.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | #import "AppDelegate.h"
9 |
10 | #import
11 | #import
12 |
13 | @implementation AppDelegate
14 |
15 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
16 | {
17 | NSURL *jsCodeLocation;
18 |
19 | jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
20 |
21 | RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
22 | moduleName:@"Example"
23 | initialProperties:nil
24 | launchOptions:launchOptions];
25 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
26 |
27 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
28 | UIViewController *rootViewController = [UIViewController new];
29 | rootViewController.view = rootView;
30 | self.window.rootViewController = rootViewController;
31 | [self.window makeKeyAndVisible];
32 | return YES;
33 | }
34 |
35 | @end
36 |
--------------------------------------------------------------------------------
/Example/ios/Example/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/Example/ios/Example/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | }
33 | ],
34 | "info" : {
35 | "version" : 1,
36 | "author" : "xcode"
37 | }
38 | }
--------------------------------------------------------------------------------
/Example/ios/Example/Images.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/Example/ios/Example/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | Example
9 | CFBundleExecutable
10 | $(EXECUTABLE_NAME)
11 | CFBundleIdentifier
12 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1
25 | LSRequiresIPhoneOS
26 |
27 | UILaunchStoryboardName
28 | LaunchScreen
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UIViewControllerBasedStatusBarAppearance
40 |
41 | NSLocationWhenInUseUsageDescription
42 |
43 | NSAppTransportSecurity
44 |
45 | NSExceptionDomains
46 |
47 | localhost
48 |
49 | NSExceptionAllowsInsecureHTTPLoads
50 |
51 |
52 |
53 |
54 | UIAppFonts
55 |
56 | Entypo.ttf
57 | EvilIcons.ttf
58 | Feather.ttf
59 | FontAwesome.ttf
60 | Foundation.ttf
61 | Ionicons.ttf
62 | MaterialCommunityIcons.ttf
63 | MaterialIcons.ttf
64 | Octicons.ttf
65 | SimpleLineIcons.ttf
66 | Zocial.ttf
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/Example/ios/Example/main.m:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015-present, Facebook, Inc.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | #import
9 |
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Example/ios/ExampleTests/ExampleTests.m:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015-present, Facebook, Inc.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | #import
9 | #import
10 |
11 | #import
12 | #import
13 |
14 | #define TIMEOUT_SECONDS 600
15 | #define TEXT_TO_LOOK_FOR @"Welcome to React Native!"
16 |
17 | @interface ExampleTests : XCTestCase
18 |
19 | @end
20 |
21 | @implementation ExampleTests
22 |
23 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
24 | {
25 | if (test(view)) {
26 | return YES;
27 | }
28 | for (UIView *subview in [view subviews]) {
29 | if ([self findSubviewInView:subview matching:test]) {
30 | return YES;
31 | }
32 | }
33 | return NO;
34 | }
35 |
36 | - (void)testRendersWelcomeScreen
37 | {
38 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
39 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
40 | BOOL foundElement = NO;
41 |
42 | __block NSString *redboxError = nil;
43 | RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
44 | if (level >= RCTLogLevelError) {
45 | redboxError = message;
46 | }
47 | });
48 |
49 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
50 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
51 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
52 |
53 | foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
54 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
55 | return YES;
56 | }
57 | return NO;
58 | }];
59 | }
60 |
61 | RCTSetLogFunction(RCTDefaultLogFunction);
62 |
63 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
64 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
65 | }
66 |
67 |
68 | @end
69 |
--------------------------------------------------------------------------------
/Example/ios/ExampleTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Example/loop.json:
--------------------------------------------------------------------------------
1 | {"v":"4.12.0","fr":29.9700012207031,"ip":0,"op":204.00000830909,"w":800,"h":600,"nm":"Comp 1","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Shape Layer 1","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[400,300,0],"ix":2},"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[360,360],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"nm":"Ellipse Path 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"tm","s":{"a":0,"k":99.7,"ix":1},"e":{"a":0,"k":100,"ix":2},"o":{"a":0,"k":2,"ix":3},"m":1,"ix":2,"nm":"Trim Paths 1","mn":"ADBE Vector Filter - Trim","hd":false},{"ty":"gs","o":{"a":0,"k":100,"ix":9},"w":{"a":0,"k":40,"ix":10},"g":{"p":3,"k":{"a":0,"k":[0,0.973,0.408,0.022,0.491,0.811,0.534,0.34,1,0.649,0.659,0.658],"ix":8}},"s":{"a":0,"k":[0,0],"ix":4},"e":{"a":0,"k":[100,0],"ix":5},"t":1,"lc":2,"lj":1,"ml":4,"nm":"Gradient Stroke 1","mn":"ADBE Vector Graphic - G-Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,20],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":0,"s":[180],"e":[898]},{"t":200.000008146167}],"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Ellipse 3","np":4,"cix":2,"ix":4,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[360,360],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"nm":"Ellipse Path 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"tm","s":{"a":0,"k":99.7,"ix":1},"e":{"a":0,"k":100,"ix":2},"o":{"a":0,"k":2,"ix":3},"m":1,"ix":2,"nm":"Trim Paths 1","mn":"ADBE Vector Filter - Trim","hd":false},{"ty":"gs","o":{"a":0,"k":100,"ix":9},"w":{"a":0,"k":40,"ix":10},"g":{"p":3,"k":{"a":0,"k":[0,0.973,0.408,0.022,0.491,0.811,0.534,0.34,1,0.649,0.659,0.658],"ix":8}},"s":{"a":0,"k":[0,0],"ix":4},"e":{"a":0,"k":[100,0],"ix":5},"t":1,"lc":2,"lj":1,"ml":4,"nm":"Gradient Stroke 1","mn":"ADBE Vector Graphic - G-Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,20],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":0,"s":[0],"e":[719]},{"t":200.000008146167}],"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Ellipse 2","np":4,"cix":2,"ix":5,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[280,280],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"nm":"Ellipse Path 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"gf","o":{"a":0,"k":100,"ix":10},"r":1,"g":{"p":3,"k":{"a":0,"k":[0,0.519,0.514,0.521,0.5,0.746,0.463,0.274,1,0.973,0.412,0.027],"ix":9}},"s":{"a":0,"k":[0,0],"ix":5},"e":{"a":0,"k":[218.086,25.777],"ix":6},"t":2,"h":{"a":0,"k":0,"ix":7},"a":{"a":0,"k":0,"ix":8},"nm":"Gradient Fill 1","mn":"ADBE Vector Graphic - G-Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[-1,19.555],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Ellipse 1","np":3,"cix":2,"ix":6,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":300.00001221925,"st":0,"bm":0}]}
--------------------------------------------------------------------------------
/Example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Example",
3 | "version": "0.0.1",
4 | "private": true,
5 | "scripts": {
6 | "start": "node node_modules/react-native/local-cli/cli.js start",
7 | "test": "jest"
8 | },
9 | "dependencies": {
10 | "lottie-react-native": "^2.5.8",
11 | "react": "16.3.1",
12 | "react-native": "0.55.4",
13 | "react-native-indicators": "^0.13.0",
14 | "react-native-smartrefreshlayout": "^0.6.3",
15 | "react-native-vector-icons": "^4.6.0"
16 | },
17 | "devDependencies": {
18 | "babel-jest": "23.0.1",
19 | "babel-preset-react-native": "4.0.0",
20 | "jest": "23.1.0",
21 | "react-test-renderer": "16.3.1"
22 | },
23 | "jest": {
24 | "preset": "react-native"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Example/untitled.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/Example/untitled.gif
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/MaterialHeader.js:
--------------------------------------------------------------------------------
1 | import React, {Component} from 'react';
2 | import {
3 | StyleSheet,
4 | View,
5 | Text,
6 | requireNativeComponent,
7 | ViewPropTypes,
8 | findNodeHandle,
9 | UIManager,
10 | } from 'react-native';
11 | import PropTypes from 'prop-types';
12 |
13 | const RCTMaterialHeader = requireNativeComponent('RCTMaterialHeader', RCTMaterialHeader);
14 |
15 | class MaterialHeader extends Component {
16 |
17 | render() {
18 | return (
19 |
22 |
23 | )
24 | }
25 | }
26 |
27 | MaterialHeader.propTypes = {
28 | ...ViewPropTypes,
29 | }
30 | export default MaterialHeader;
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React Native SmartRefreshLayout [](https://badge.fury.io/js/react-native-smartrefreshlayout)
2 |
3 | >React-Native-SmartRefreshLayout是基于[Android SmartRefreshLayout](https://github.com/scwang90/SmartRefreshLayout) 开发的插件
4 | >,
可提供类似ios的弹性刷新,该插件可完全使用React Native进行自定义
5 | >
6 | >HeaderComponent现在支持任意的RN组件,但是需要放在AnyHeader的组件中,
其中onHeaderPulling、onHeaderReleasing和onHeaderMoving的参数为{nativeEvent:{percent,offset,headerHeight}},可用来控制下拉和释放过程中更为精细的动画,
7 | > 如果下拉和释放过程不需要过程动画,则使用onPullDownToRefresh和onReleaseToRefresh即可实现。
8 | >
请看示例:Example
[HuaweiRefreshControl](https://github.com/react-native-studio/react-native-SmartRefreshLayout/blob/master/Example/HuaWeiRefreshControl.js)
9 | >、 [LottieRefreshControl](https://github.com/react-native-studio/react-native-SmartRefreshLayout/blob/master/Example/LottieRefreshControl.js)
10 | >
11 | >IOS自定义下拉刷新组件见[React-Native-MJRefresh](https://github.com/react-native-studio/react-native-MJRefresh)
12 | >
13 | >
14 |
15 |
16 | >建议:该组件与[lottie-react-native](https://github.com/react-community/lottie-react-native)配合使用可获得绝佳的下拉动画效果
17 |
18 | ## 安装
19 | #### 第一步
20 | 工程目录下运行:
21 |
22 | ```bash
23 | npm install --save react-native-smartrefreshlayout
24 | ```
25 |
26 | or (已经安装了yarn)
27 |
28 |
29 | ```bash
30 | yarn add react-native-smartrefreshlayout
31 | ```
32 |
33 |
34 | #### 第二步
35 | 工程目录下运行:
36 | ```bash
37 | react-native link react-native-smartrefreshlayout
38 | ```
39 |
40 | ## 使用
41 | 在工程中导入:
42 | ```js
43 | import {SmartRefreshControl,DefaultHeader} from 'react-native-smartrefreshlayout';
44 | //使用方法和RN官方的RefreshControl类似,
45 | this.rc = ref}
48 | HeaderComponent={}
49 | onRefresh={() => {
50 | setTimeout(() => {
51 | this.rc && this.rc.finishRefresh();
52 | }, 1000)
53 | }}
54 | />}
55 | >
56 |
57 | ```
58 | ## 组件
59 | ### SmartRefreshControl
60 | 其他组件查看[AnyHeader](./docs/AnyHeader.md)、[DefaultHeader](./docs/DefaultHeader.md)、[ClassicsHeader](./docs/DefaultHeader.md)、[StoreHouseHeader](./docs/StoreHouse.md)
61 | #### 查看属性
62 | - [`HeaderComponent`](README.md#headercomponent)
63 | - [`renderHeader`](README.md#renderHeader)
64 | - [`enableRefresh`](README.md#enablerefresh)
65 | - [`headerHeight`](README.md#headerHeight)
66 | - [`primaryColor`](README.md#primarycolor)
67 | - [`autoRefresh`](README.md#autorefresh)
68 | - [`pureScroll`](README.md#purescroll)
69 | - [`overScrollBounce`](README.md#overscrollbounce)
70 | - [`overScrollDrag`](README.md#overscrolldrag)
71 | - [`dragRate`](README.md#dragrate)
72 | - [`maxDragRate`](README.md#maxdragrate)
73 | - [`onRefresh`](README.md#onrefresh)
74 | - [`onPullDownToRefresh`](README.md#onpulldowntorefresh)
75 | - [`onReleaseToRefresh`](README.md#onreleasetorefresh)
76 | - [`onHeaderPulling`](README.md#onheaderpulling)
77 | - [`onHeaderReleasing`](README.md#onheaderreleasing)
78 | - [`onHeaderReleased`](README.md#onheaderreleased)
79 | - [`onHeaderMoving`](README.md#onheadermoving)
80 |
81 | #### 查看方法
82 |
83 | - [`finishRefresh`](README.md#finishrefresh)
84 |
85 | ## 文档
86 |
87 | ### Props
88 |
89 | #### `HeaderComponent`
90 |
91 | 用于渲染SmartRefreshLayout组件的header,默认为DefaultHeader。
92 |
93 | >**NOTE**
94 | >
95 | >必须传入插件中给出的Header组件,如AnyHeader,DefaultHeader等
96 |
97 | | Type | Required |
98 | | ---- | -------- |
99 | | Element | No |
100 |
101 | ---
102 |
103 | #### `renderHeader`
104 |
105 | 用于渲染SmartRefreshLayout组件的header,默认为DefaultHeader。
106 |
107 | >**NOTE**
108 | >
109 | >必须传入插件中给出的Header组件,如AnyHeader,DefaultHeader等
110 |
111 | | Type | Required |
112 | | ---- | -------- |
113 | | Element/func | No |
114 |
115 | ---
116 |
117 | #### `enableRefresh`
118 |
119 | 是否启用下拉刷新,默认为true
120 |
121 | | Type | Required |
122 | | ---- | -------- |
123 | | boolean | No |
124 |
125 | ---
126 |
127 | #### `headerHeight`
128 |
129 | 设定header的高度
130 |
131 | >**NOTE**
132 | >
133 | >自定义 header 时应指定headerHeight。
134 |
135 | | Type | Required |
136 | | ---- | -------- |
137 | | number | No |
138 |
139 | ---
140 |
141 | #### `primaryColor`
142 |
143 | 设置刷新组件的主调色
144 |
145 | | Type | Required |
146 | | ---- | -------- |
147 | | string | No |
148 |
149 | ---
150 |
151 | #### `autoRefresh`
152 | >***NOTE***
153 | >
154 | >time字段含义:延迟time毫秒后自动刷新
155 |
156 | 是否自动刷新
157 |
158 | | Type | Required |
159 | | ---- | -------- |
160 | | object:{refresh:boolean, time:number} | No |
161 |
162 | ---
163 |
164 | #### `pureScroll`
165 |
166 | 是否启用纯滚动
167 |
168 | | Type | Required |
169 | | ---- | -------- |
170 | | boolean | No |
171 |
172 | ---
173 |
174 | #### `overScrollBounce`
175 |
176 | 是否允许越界回弹
177 |
178 | | Type | Required |
179 | | ---- | -------- |
180 | | boolean | No |
181 |
182 | ---
183 |
184 | #### `overScrollDrag`
185 |
186 | 是否启用越界拖动,类似IOS样式。
187 |
188 | | Type | Required |
189 | | ---- | -------- |
190 | | boolean | No |
191 |
192 | ---
193 |
194 | #### `dragRate`
195 |
196 | 设置组件下拉高度与手指真实下拉高度的比值,默认为0.5。
197 |
198 | | Type | Required |
199 | | ---- | -------- |
200 | | number | No |
201 |
202 | ---
203 |
204 | #### `maxDragRate`
205 |
206 | 设置最大显示下拉高度与header标准高度的比值,默认为2.0。
207 |
208 | | Type | Required |
209 | | ---- | -------- |
210 | | number | No |
211 |
212 | ---
213 |
214 | #### `onPullDownToRefresh`
215 |
216 | 可下拉刷新时触发
217 |
218 | | Type | Required |
219 | | ---- | -------- |
220 | | function | No |
221 |
222 | ---
223 |
224 | #### `onReleaseToRefresh`
225 |
226 | 可释放刷新时触发
227 |
228 | | Type | Required |
229 | | ---- | -------- |
230 | | function | No |
231 |
232 | ---
233 |
234 | #### `onRefresh`
235 |
236 | 刷新时触发
237 |
238 | | Type | Required |
239 | | ---- | -------- |
240 | | function | No |
241 |
242 | ---
243 |
244 | #### `onHeaderReleased`
245 |
246 | Header释放时触发
247 |
248 | | Type | Required |
249 | | ---- | -------- |
250 | | function | No |
251 |
252 | ---
253 |
254 | #### `onHeaderPulling`
255 |
256 | ```javascript
257 | ({nativeEvent: {percent:number, offset:number, headerHeight:number}})=>void;
258 | ```
259 | header下拉过程中触发
260 |
261 | | Type | Required |
262 | | ---- | -------- |
263 | | function | No |
264 |
265 | ---
266 |
267 | #### `onHeaderReleasing`
268 |
269 | ```javascript
270 | ({nativeEvent: {percent:number, offset:number, headerHeight:number}})=>void;
271 | ```
272 | header释放过程中触发
273 |
274 | | Type | Required |
275 | | ---- | -------- |
276 | | function | No |
277 |
278 | ---
279 |
280 | #### `onHeaderMoving`
281 |
282 | ```javascript
283 | ({nativeEvent: {percent:number, offset:number, headerHeight:number}})=>void;
284 | ```
285 | header移动过程中触发,包括下拉过程和释放过程。
286 |
287 | | Type | Required |
288 | | ---- | -------- |
289 | | function | No |
290 |
291 | ### Methods
292 |
293 | #### `finishRefresh`
294 |
295 | ```javascript
296 | finishRefresh([params]);
297 | ```
298 |
299 | 完成刷新
300 |
301 | | Name | Type | Required|
302 | | ---- | -------- |-----|
303 | | params | object | NO |
304 |
305 | Valid `params` keys are:
306 | * `delayed` (number) - 延迟完成刷新的时间
307 | * `success` (boolean) - 是否刷新成功,暂时没有影响
308 |
309 |
310 | ## 示例
311 |
312 |
317 |
318 |
319 |
--------------------------------------------------------------------------------
/SmartRefreshControl.js:
--------------------------------------------------------------------------------
1 | import React, {Component} from 'react';
2 | import {
3 | StyleSheet,
4 | View,
5 | Text,
6 | requireNativeComponent,
7 | findNodeHandle,
8 | UIManager,
9 | NativeModules,
10 | Platform,
11 | PanResponder,
12 | } from 'react-native';
13 | import {ViewPropTypes} from './Util'
14 | import DefaultHeader from "./DefaultHeader";
15 | import PropTypes from 'prop-types';
16 | import processColor from 'react-native/Libraries/StyleSheet/processColor';
17 | import deprecatedPropType from 'react-native/Libraries/Utilities/deprecatedPropType'
18 |
19 | const SPModule =Platform.OS === 'android' ? NativeModules.SpinnerStyleModule : {};
20 |
21 | const SmartRefreshLayout = requireNativeComponent('SmartRefreshLayout', SmartRefreshControl);
22 |
23 | class SmartRefreshControl extends Component {
24 | static constants = {
25 | "TRANSLATE":SPModule.translate,
26 | "SCALE":SPModule.scale,
27 | "FIX_BEHIND":SPModule.fixBehind,
28 | "FIX_FRONT":SPModule.fixFront,
29 | "MATCH_LAYOUT":SPModule.matchLayout,
30 | }
31 |
32 |
33 | /**
34 | * 参数格式为{delayed:number,success:bool}
35 | * delayed:延迟刷新
36 | * success:是否刷新成功
37 | * @param params
38 | */
39 | finishRefresh=({delayed=-1,success=true}={delayed:-1,success:true})=>{
40 | this.dispatchCommand('finishRefresh',[delayed,success])
41 | }
42 | dispatchCommand=(commandName, params)=>{
43 | UIManager.dispatchViewManagerCommand(this.findNode(),
44 | (UIManager.getViewManagerConfig ? UIManager.getViewManagerConfig("SmartRefreshLayout"): UIManager.SmartRefreshLayout).Commands[commandName],
45 | params);
46 | }
47 | findNode=()=>{
48 |
49 | return findNodeHandle(this.refs.refreshLayout);
50 | }
51 | componentWillMount() {
52 | this._panResponder = PanResponder.create({
53 | onMoveShouldSetPanResponderCapture: (evt, gestureState) => {
54 | if(this.shiftPercent >= 0.039 || this.footerShiftPercent >= 0.068){//满足条件捕获事件
55 | return true
56 | }
57 | return false;
58 | }
59 | });
60 | }
61 |
62 | shiftPercent = 0;//header位移百分比,默认为0
63 |
64 | footerShiftPercent = 0; // footer位移百分比
65 | /**
66 | * 渲染Header
67 | * @return {*}
68 | */
69 | renderHeader=()=>{
70 | const {HeaderComponent,renderHeader}=this.props;
71 | if(renderHeader){
72 | return React.isValidElement(renderHeader)?renderHeader:renderHeader();
73 | }
74 | if(HeaderComponent){
75 | return HeaderComponent;
76 | }
77 | return
78 | }
79 | /**
80 | * 刷新时触发
81 | * @private
82 | */
83 | _onSmartRefresh=()=>{
84 | let {onRefresh} = this.props;
85 | onRefresh && onRefresh();
86 | }
87 | /**
88 | * 下拉过程
89 | * @param event
90 | * @private
91 | */
92 | _onHeaderPulling=(event)=>{
93 | this.shiftPercent = event.nativeEvent.percent;
94 | let {onHeaderPulling,onHeaderMoving} = this.props;
95 | onHeaderMoving && onHeaderMoving(event);
96 | onHeaderPulling && onHeaderPulling(event);
97 | }
98 | /**
99 | * 释放过程
100 | * @param event
101 | * @private
102 | */
103 | _onHeaderReleasing=(event)=>{
104 | this.shiftPercent = event.nativeEvent.percent;
105 | let {onHeaderReleasing,onHeaderMoving} = this.props;
106 | onHeaderMoving && onHeaderMoving(event);
107 | onHeaderReleasing && onHeaderReleasing(event);
108 | }
109 | /**
110 | * 底部位移过程
111 | * @param event
112 | * @private
113 | */
114 | _onFooterMoving=(event)=>{
115 | this.footerShiftPercent = event.nativeEvent.percent;
116 | }
117 |
118 | render() {
119 | const nativeProps ={...this.props,...{
120 | onSmartRefresh:this._onSmartRefresh,
121 | onHeaderPulling:this._onHeaderPulling,
122 | onHeaderReleasing:this._onHeaderReleasing,
123 | onFooterMoving:this._onFooterMoving,
124 | primaryColor: processColor(this.props.primaryColor),
125 | }}
126 | return (
127 |
132 | {this.renderHeader()}
133 | {this.props.children}
134 |
135 |
136 | )
137 | }
138 | }
139 |
140 | SmartRefreshControl.propTypes = {
141 | onRefresh: PropTypes.func,
142 | onLoadMore: PropTypes.func,
143 | onHeaderPulling:PropTypes.func,
144 | onHeaderReleasing:PropTypes.func,
145 | onHeaderMoving:PropTypes.func,//向外提供的接口
146 | onPullDownToRefresh:PropTypes.func,
147 | onReleaseToRefresh:PropTypes.func,
148 | onHeaderReleased:PropTypes.func,
149 | enableRefresh: PropTypes.bool,//是否启用下拉刷新功能
150 | HeaderComponent:deprecatedPropType(PropTypes.object,'Use the `renderHeader` prop instead.'),
151 | renderHeader:PropTypes.oneOfType([
152 | PropTypes.func,
153 | PropTypes.element,
154 | ]),
155 | headerHeight:PropTypes.number,
156 | overScrollBounce:PropTypes.bool,//是否使用越界回弹
157 | overScrollDrag:PropTypes.bool,//是否使用越界拖动,类似IOS样式
158 | pureScroll:PropTypes.bool,//是否使用纯滚动模式
159 | dragRate:PropTypes.number,// 显示下拉高度/手指真实下拉高度=阻尼效果
160 | maxDragRate:PropTypes.number,//最大显示下拉高度/Header标准高度
161 | primaryColor:PropTypes.string,
162 | autoRefresh:PropTypes.shape({
163 | refresh:PropTypes.bool,
164 | time:PropTypes.number,
165 | }),//是否启动自动刷新
166 | ...ViewPropTypes,
167 | }
168 |
169 | SmartRefreshControl.defaultProps={
170 | overScrollBounce:false
171 | }
172 | export default SmartRefreshControl;
--------------------------------------------------------------------------------
/StoreHouseHeader.js:
--------------------------------------------------------------------------------
1 | import React, {Component} from 'react';
2 | import {requireNativeComponent} from 'react-native';
3 | import {ViewPropTypes} from "./Util";
4 | import PropTypes from 'prop-types';
5 |
6 | const RCTStoreHouseHeader = requireNativeComponent('RCTStoreHouseHeader', RCTStoreHouseHeader);
7 |
8 | export default class StoreHouseHeader extends Component {
9 | static propTypes = {
10 | textColor: PropTypes.string,
11 | text: PropTypes.string,//暂时只支持英文
12 | fontSize: PropTypes.number,
13 | lineWidth: PropTypes.number,
14 | dropHeight: PropTypes.number,
15 | ...ViewPropTypes,
16 | }
17 |
18 | render() {
19 | return ()
20 | }
21 | }
--------------------------------------------------------------------------------
/Util.js:
--------------------------------------------------------------------------------
1 | import {
2 | View,
3 | BackHandler,
4 | ViewPropTypes as RNViewPropTypes,
5 | BackAndroid as DeprecatedBackAndroid,
6 | } from 'react-native';
7 |
8 | export const ViewPropTypes = RNViewPropTypes || View.propTypes;
9 | export const BackAndroid = BackHandler || DeprecatedBackAndroid;
10 |
--------------------------------------------------------------------------------
/android/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | def safeExtGet(prop, fallback) {
4 | rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
5 | }
6 |
7 | android {
8 | compileSdkVersion safeExtGet("compileSdkVersion",25)
9 | buildToolsVersion safeExtGet("buildToolsVersion","25.0.2")
10 |
11 | defaultConfig {
12 | minSdkVersion safeExtGet('minSdkVersion', 16)
13 | targetSdkVersion safeExtGet('targetSdkVersion', 26)
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
18 |
19 | }
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | }
27 |
28 | dependencies {
29 | compile "com.facebook.react:react-native:+"
30 | compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.5.1'
31 | compile 'com.scwang.smartrefresh:SmartRefreshHeader:1.0.5.1'//没有使用特殊Header,可以不加这行
32 | }
33 |
--------------------------------------------------------------------------------
/android/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/painter.g/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/android/smartrefreshlayout.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateDebugSources
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 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
--------------------------------------------------------------------------------
/android/src/androidTest/java/com/lmy/smartrefreshlayout/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.lmy.smartrefreshlayout;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.lmy.smartrefreshlayout.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/android/src/main/java/com/lmy/header/AnyHeader.java:
--------------------------------------------------------------------------------
1 | package com.lmy.header;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.BitmapDrawable;
5 | import android.support.annotation.ColorInt;
6 | import android.support.annotation.NonNull;
7 | import android.view.View;
8 |
9 | import com.facebook.react.views.view.ReactViewGroup;
10 | import com.scwang.smartrefresh.layout.api.RefreshHeader;
11 | import com.scwang.smartrefresh.layout.api.RefreshKernel;
12 | import com.scwang.smartrefresh.layout.api.RefreshLayout;
13 | import com.scwang.smartrefresh.layout.constant.RefreshState;
14 | import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
15 | import com.scwang.smartrefresh.layout.util.DensityUtil;
16 |
17 | /**anyview
18 | * Created by painter.g on 2018/3/9.
19 | */
20 |
21 | public class AnyHeader extends ReactViewGroup implements RefreshHeader {
22 | private RefreshKernel mRefreshKernel;
23 | private int mBackgroundColor;
24 | private Integer mPrimaryColor;
25 | private SpinnerStyle mSpinnerStyle = SpinnerStyle.Translate;
26 |
27 | public AnyHeader(Context context) {
28 | super(context);
29 | initView(context);
30 | }
31 | @Override
32 | public void onInitialized(@NonNull RefreshKernel kernel, int height, int extendHeight) {
33 | mRefreshKernel = kernel;
34 | mRefreshKernel.requestDrawBackgroundForHeader(mBackgroundColor);
35 | }
36 | private void initView(Context context) {
37 | setMinimumHeight(DensityUtil.dp2px(60));
38 | }
39 | public void setView(View v){
40 | addView(v);
41 | }
42 | @NonNull
43 | public View getView() {
44 | return this;//真实的视图就是自己,不能返回null
45 | }
46 |
47 | @Override
48 | public SpinnerStyle getSpinnerStyle() {
49 | return this.mSpinnerStyle;//指定为平移,不能null
50 | }
51 |
52 | /**
53 | * 设置主题色
54 | * @param colors
55 | */
56 | @Override
57 | public void setPrimaryColors(int... colors) {
58 | if(colors.length>0) {
59 | if (!(getBackground() instanceof BitmapDrawable) && mPrimaryColor == null) {
60 | setPrimaryColor(colors[0]);
61 | mPrimaryColor = null;
62 | }
63 | }
64 | }
65 |
66 | public AnyHeader setPrimaryColor(@ColorInt int primaryColor) {
67 | mBackgroundColor = mPrimaryColor =primaryColor;
68 | if (mRefreshKernel != null) {
69 | mRefreshKernel.requestDrawBackgroundForHeader(mPrimaryColor);
70 | }
71 | return this;
72 | }
73 |
74 | public AnyHeader setSpinnerStyle(SpinnerStyle style){
75 | this.mSpinnerStyle = style;
76 | return this;
77 | }
78 | @Override
79 | public void onPulling(float percent, int offset, int height, int extendHeight) {
80 |
81 | }
82 |
83 | @Override
84 | public void onReleasing(float percent, int offset, int height, int extendHeight) {
85 |
86 | }
87 |
88 | @Override
89 | public void onReleased(RefreshLayout refreshLayout, int height, int extendHeight) {
90 |
91 | }
92 |
93 | @Override
94 | public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int extendHeight) {
95 |
96 | }
97 |
98 | @Override
99 | public int onFinish(@NonNull RefreshLayout refreshLayout, boolean success) {
100 | return 500;//延迟500毫秒之后再弹回
101 | }
102 |
103 | @Override
104 | public void onHorizontalDrag(float percentX, int offsetX, int offsetMax) {
105 |
106 | }
107 |
108 | @Override
109 | public boolean isSupportHorizontalDrag() {
110 | return false;
111 | }
112 |
113 | @Override
114 | public void onStateChanged(RefreshLayout refreshLayout, RefreshState oldState, RefreshState newState) {
115 |
116 | }
117 | /*@Override
118 | protected void onFinishInflate() {
119 | int childCount = getChildCount();
120 | for(int i=0;i {
19 | @Override
20 | public String getName() {
21 | return "RCTAnyHeader";
22 | }
23 |
24 | @Override
25 | protected AnyHeader createViewInstance(ThemedReactContext reactContext) {
26 | return new AnyHeader(reactContext);
27 | }
28 |
29 | /**
30 | * 设置主调色
31 | * @param view
32 | * @param primaryColor
33 | */
34 | @ReactProp(name = "primaryColor")
35 | public void setPrimaryColor(AnyHeader view, String primaryColor){
36 | if(primaryColor!=null && !"".equals(primaryColor)){
37 | view.setPrimaryColor(Color.parseColor(primaryColor));
38 | }
39 | }
40 |
41 | /**
42 | * 设置spinnerStyle
43 | * @param view
44 | * @param spinnerStyle
45 | */
46 | @ReactProp(name = "spinnerStyle")
47 | public void setSpinnerStyle(AnyHeader view,String spinnerStyle){
48 | view.setSpinnerStyle(SpinnerStyleConstants.SpinnerStyleMap.get(spinnerStyle));
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/android/src/main/java/com/lmy/header/ClassicsHeaderManager.java:
--------------------------------------------------------------------------------
1 | package com.lmy.header;
2 |
3 | import android.graphics.Color;
4 |
5 | import com.facebook.react.uimanager.SimpleViewManager;
6 | import com.facebook.react.uimanager.ThemedReactContext;
7 | import com.facebook.react.uimanager.annotations.ReactProp;
8 | import com.scwang.smartrefresh.layout.header.ClassicsHeader;
9 |
10 | /**
11 | * Created by painter.g on 2018/3/7.
12 | */
13 |
14 | public class ClassicsHeaderManager extends SimpleViewManager {
15 | @Override
16 | public String getName() {
17 | return "RCTClassicsHeader";
18 | }
19 |
20 | @Override
21 | protected ClassicsHeader createViewInstance(ThemedReactContext reactContext) {
22 | return new ClassicsHeader(reactContext);
23 | }
24 |
25 | /**
26 | * 设置主题颜色
27 | * @param view
28 | * @param primaryColor
29 | */
30 | @ReactProp(name = "primaryColor")
31 | public void setPrimaryColor(ClassicsHeader view,String primaryColor){
32 | view.setPrimaryColor(Color.parseColor(primaryColor));
33 | }
34 |
35 | /**
36 | * 设置强调颜色
37 | * @param view
38 | * @param accentColor
39 | */
40 | @ReactProp(name = "accentColor")
41 | public void setAccentColor(ClassicsHeader view,String accentColor){
42 | view.setAccentColor(Color.parseColor(accentColor));
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/android/src/main/java/com/lmy/header/DefaultHeader.java:
--------------------------------------------------------------------------------
1 | package com.lmy.header;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.ColorInt;
5 | import android.support.annotation.NonNull;
6 | import android.support.annotation.Nullable;
7 | import android.util.AttributeSet;
8 | import android.view.Gravity;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.ImageView;
12 | import android.widget.LinearLayout;
13 | import android.widget.RelativeLayout;
14 | import android.widget.TextView;
15 |
16 | import com.facebook.drawee.components.DeferredReleaser;
17 | import com.lmy.smartrefreshlayout.R;
18 | import com.scwang.smartrefresh.layout.api.RefreshHeader;
19 | import com.scwang.smartrefresh.layout.api.RefreshKernel;
20 | import com.scwang.smartrefresh.layout.api.RefreshLayout;
21 | import com.scwang.smartrefresh.layout.constant.RefreshState;
22 | import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
23 | import com.scwang.smartrefresh.layout.internal.ProgressDrawable;
24 | import com.scwang.smartrefresh.layout.internal.pathview.PathsView;
25 | import com.scwang.smartrefresh.layout.util.DensityUtil;
26 |
27 | /**
28 | * Created by painter.g on 2018/3/12.
29 | */
30 |
31 | public class DefaultHeader extends RelativeLayout implements RefreshHeader {
32 | private TextView mHeaderText;//标题文本
33 | private PathsView mArrowView;//下拉箭头
34 | private ImageView mProgressView;//刷新动画视图
35 | private ProgressDrawable mProgressDrawable;//刷新动画
36 | protected RefreshKernel mRefreshKernel;
37 | protected int mBackgroundColor;
38 | protected int mAccentColor;
39 |
40 | public DefaultHeader(Context context) {
41 | super(context);
42 | this.initView(context);
43 | }
44 |
45 | public DefaultHeader(Context context, @Nullable AttributeSet attrs) {
46 | super(context, attrs);
47 | this.initView(context);
48 | }
49 |
50 | public DefaultHeader(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
51 | super(context, attrs, defStyleAttr);
52 | this.initView(context);
53 | }
54 |
55 |
56 | private void initView(Context context) {
57 | RelativeLayout parent = new RelativeLayout(context);
58 | RelativeLayout.LayoutParams rlParent = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
59 | rlParent.addRule(RelativeLayout.CENTER_IN_PARENT,RelativeLayout.TRUE);
60 |
61 |
62 | RelativeLayout.LayoutParams rlArrowView = new RelativeLayout.LayoutParams(DensityUtil.dp2px(20),DensityUtil.dp2px(20));
63 | mArrowView = new PathsView(context);
64 | mArrowView.setId(R.id.arrow_view);
65 | mArrowView.parserColors(0xff666666);
66 | mArrowView.parserPaths("M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z");
67 | parent.addView(mArrowView,rlArrowView);
68 |
69 |
70 | RelativeLayout.LayoutParams rlHeaderText= new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
71 | rlHeaderText.addRule(RelativeLayout.RIGHT_OF,mArrowView.getId());
72 | rlHeaderText.leftMargin = DensityUtil.dp2px(20);
73 | mHeaderText = new TextView(context);
74 | mHeaderText.setText("下拉开始刷新");
75 | parent.addView(mHeaderText,rlHeaderText);
76 |
77 | RelativeLayout.LayoutParams rlProgressView = new RelativeLayout.LayoutParams(DensityUtil.dp2px(20),DensityUtil.dp2px(20));
78 | rlProgressView.addRule(RelativeLayout.ALIGN_RIGHT,mArrowView.getId());
79 | mProgressDrawable = new ProgressDrawable();
80 | mProgressView = new ImageView(context);
81 | mProgressView.setImageDrawable(mProgressDrawable);
82 | parent.addView(mProgressView,rlProgressView);
83 |
84 |
85 | addView(parent,rlParent);
86 | //addView(mProgressView, DensityUtil.dp2px(20), DensityUtil.dp2px(20));
87 | //addView(mArrowView, DensityUtil.dp2px(20), DensityUtil.dp2px(20));
88 | //addView(new View(context), DensityUtil.dp2px(20), DensityUtil.dp2px(20));
89 | //addView(mHeaderText, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
90 | setMinimumHeight(DensityUtil.dp2px(60));
91 | }
92 |
93 | @NonNull
94 | public View getView() {
95 | return this;//真实的视图就是自己,不能返回null
96 | }
97 |
98 | @Override
99 | public SpinnerStyle getSpinnerStyle() {
100 | return SpinnerStyle.Translate;//指定为平移,不能null
101 | }
102 |
103 | @Override
104 | public void onStartAnimator(RefreshLayout layout, int headHeight, int extendHeight) {
105 | mProgressDrawable.start();//开始动画
106 | }
107 |
108 | @Override
109 | public int onFinish(RefreshLayout layout, boolean success) {
110 | mProgressDrawable.stop();//停止动画
111 | if (success) {
112 | mHeaderText.setText("刷新完成");
113 | } else {
114 | mHeaderText.setText("刷新失败");
115 | }
116 | return 500;//延迟500毫秒之后再弹回
117 | }
118 | @Override
119 | public void onStateChanged(RefreshLayout refreshLayout, RefreshState oldState, RefreshState newState) {
120 | switch (newState) {
121 | case None:
122 | case PullDownToRefresh:
123 | mHeaderText.setText("下拉开始刷新");
124 | mArrowView.setVisibility(VISIBLE);//显示下拉箭头
125 | mProgressView.setVisibility(GONE);//隐藏动画
126 | mArrowView.animate().rotation(0);//还原箭头方向
127 | break;
128 | case Refreshing:
129 | mHeaderText.setText("正在刷新");
130 | mProgressView.setVisibility(VISIBLE);//显示加载动画
131 | mArrowView.setVisibility(GONE);//隐藏箭头
132 | break;
133 | case ReleaseToRefresh:
134 | mHeaderText.setText("释放立即刷新");
135 | mArrowView.animate().rotation(180);//显示箭头改为朝上
136 | break;
137 | }
138 | }
139 |
140 | @Override
141 | public boolean isSupportHorizontalDrag() {
142 | return false;
143 | }
144 |
145 | @Override
146 | public void onInitialized(RefreshKernel kernel, int height, int extendHeight) {
147 | mRefreshKernel = kernel;
148 | mRefreshKernel.requestDrawBackgroundForHeader(mBackgroundColor);
149 |
150 | }
151 |
152 | @Override
153 | public void onHorizontalDrag(float percentX, int offsetX, int offsetMax) {
154 | }
155 |
156 | @Override
157 | public void onPulling(float percent, int offset, int headHeight, int extendHeight) {
158 | }
159 |
160 | @Override
161 | public void onReleasing(float percent, int offset, int headHeight, int extendHeight) {
162 | }
163 |
164 | @Override
165 | public void onReleased(RefreshLayout refreshLayout, int height, int extendHeight) {
166 |
167 | }
168 |
169 | @Override
170 | public void setPrimaryColors(@ColorInt int... colors) {
171 | }
172 |
173 | public DefaultHeader setPrimaryColor(@ColorInt int primaryColor) {
174 | mBackgroundColor = primaryColor;
175 | if (mRefreshKernel != null) {
176 | mRefreshKernel.requestDrawBackgroundForHeader(primaryColor);
177 | }
178 | return this;
179 | }
180 | public DefaultHeader setAccentColor(int accentColor){
181 | mAccentColor=accentColor;
182 | if(mArrowView!=null){
183 | mArrowView.parserColors(accentColor);
184 | }
185 | if(mProgressDrawable!=null) {
186 | mProgressDrawable.setColor(accentColor);
187 | }
188 | mHeaderText.setTextColor(accentColor);
189 | return this;
190 | }
191 |
192 | }
193 |
--------------------------------------------------------------------------------
/android/src/main/java/com/lmy/header/DefaultHeaderMananger.java:
--------------------------------------------------------------------------------
1 | package com.lmy.header;
2 |
3 | import android.graphics.Color;
4 |
5 | import com.facebook.react.uimanager.SimpleViewManager;
6 | import com.facebook.react.uimanager.ThemedReactContext;
7 | import com.facebook.react.uimanager.annotations.ReactProp;
8 |
9 | /**
10 | * Created by painter.g on 2018/3/12.
11 | */
12 |
13 | public class DefaultHeaderMananger extends SimpleViewManager {
14 | @Override
15 | public String getName() {
16 | return "RCTDefaultHeader";
17 | }
18 |
19 | @Override
20 | protected DefaultHeader createViewInstance(ThemedReactContext reactContext) {
21 | return new DefaultHeader(reactContext);
22 | }
23 | /**
24 | * 设置主题颜色
25 | * @param view
26 | * @param primaryColor
27 | */
28 | @ReactProp(name = "primaryColor")
29 | public void setPrimaryColor(DefaultHeader view,String primaryColor){
30 | view.setPrimaryColor(Color.parseColor(primaryColor));
31 | }
32 |
33 | /**
34 | * 设置强调颜色
35 | * @param view
36 | * @param accentColor
37 | */
38 | @ReactProp(name = "accentColor")
39 | public void setAccentColor(DefaultHeader view,String accentColor){
40 | view.setAccentColor(Color.parseColor(accentColor));
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/android/src/main/java/com/lmy/header/MaterialHeaderManager.java:
--------------------------------------------------------------------------------
1 | package com.lmy.header;
2 |
3 | import com.facebook.react.uimanager.ThemedReactContext;
4 | import com.facebook.react.uimanager.ViewGroupManager;
5 | import com.scwang.smartrefresh.header.MaterialHeader;
6 |
7 | /**
8 | * Created by painter.g on 2018/3/8.
9 | */
10 |
11 | public class MaterialHeaderManager extends ViewGroupManager {
12 | @Override
13 | public String getName() {
14 | return "RCTMaterialHeader";
15 | }
16 |
17 | @Override
18 | protected MaterialHeader createViewInstance(ThemedReactContext reactContext) {
19 | return new MaterialHeader(reactContext);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/android/src/main/java/com/lmy/header/StoreHouseHeaderManager.java:
--------------------------------------------------------------------------------
1 | package com.lmy.header;
2 |
3 | import android.graphics.Color;
4 |
5 | import com.facebook.react.uimanager.SimpleViewManager;
6 | import com.facebook.react.uimanager.ThemedReactContext;
7 | import com.facebook.react.uimanager.annotations.ReactProp;
8 | import com.scwang.smartrefresh.header.StoreHouseHeader;
9 |
10 | /**
11 | * Created by painter.g on 2018/3/7.
12 | */
13 |
14 | public class StoreHouseHeaderManager extends SimpleViewManager {
15 |
16 | private String textStr="STOREHOUSE";
17 | @Override
18 | public String getName() {
19 | return "RCTStoreHouseHeader";
20 | }
21 |
22 | @Override
23 | protected StoreHouseHeader createViewInstance(ThemedReactContext reactContext) {
24 | return new StoreHouseHeader(reactContext);
25 | }
26 |
27 | /**
28 | * 设置字体颜色
29 | * @param view
30 | * @param textColor
31 | */
32 | @ReactProp(name = "textColor")
33 | public void setTextColor(StoreHouseHeader view,String textColor){
34 | view.setTextColor(Color.parseColor(textColor));
35 | }
36 |
37 | /**
38 | * 设置文字
39 | * @param view
40 | * @param text
41 | */
42 | @ReactProp(name="text")
43 | public void setText(StoreHouseHeader view,String text){
44 | textStr=text;
45 | view.initWithString(text);
46 | }
47 |
48 | /**
49 | * 设置字体尺寸
50 | * TODO:似乎还没有作用
51 | * @param view
52 | * @param fontSize
53 | */
54 | @ReactProp(name="fontSize",defaultInt = 25)
55 | public void setFontSize(StoreHouseHeader view,int fontSize){
56 | view.initWithString(textStr,fontSize);
57 | }
58 |
59 | /**
60 | * 设置线宽
61 | * @param view
62 | * @param lineWidth
63 | */
64 | @ReactProp(name = "lineWidth")
65 | public void setLineWidth(StoreHouseHeader view,int lineWidth){
66 | view.setLineWidth(lineWidth);
67 | }
68 |
69 | /**
70 | * 设置dropHeight
71 | * TODO:似乎还没有作用
72 | * @param view
73 | * @param dropHeight
74 | */
75 | @ReactProp(name="dropHeight")
76 | public void setDropHeight(StoreHouseHeader view,int dropHeight){
77 | view.setDropHeight(dropHeight);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/android/src/main/java/com/lmy/smartrefreshlayout/Events.java:
--------------------------------------------------------------------------------
1 | package com.lmy.smartrefreshlayout;
2 |
3 | /**
4 | * Created by lmy2534290808 on 2017/12/2.
5 | */
6 |
7 | public enum Events {
8 | REFRESH("onSmartRefresh"),//刷新触发
9 | LOAD_MORE("onLoadMore"),//加载更多触发
10 | HEADER_PULLING("onHeaderPulling"),//header下拉触发
11 | HEADER_RELEASING("onHeaderReleasing"),//header刷新完成后触发
12 | PULL_DOWN_TO_REFRESH("onPullDownToRefresh"),//下拉开始刷新
13 | RELEASE_TO_REFRESH("onReleaseToRefresh"),//释放刷新
14 | HEADER_RELEASED("onHeaderReleased"),//释放时进行刷新
15 | FOOTER_MOVING("onFooterMoving");//footer移动时触发
16 |
17 | private final String mName;
18 |
19 | Events(final String name) {
20 | mName = name;
21 | }
22 |
23 | @Override
24 | public String toString() {
25 | return mName;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/android/src/main/java/com/lmy/smartrefreshlayout/HeaderType.java:
--------------------------------------------------------------------------------
1 | package com.lmy.smartrefreshlayout;
2 |
3 | /**
4 | * Created by painter.g on 2018/3/7.
5 | */
6 |
7 | public class HeaderType {
8 | public static final String CLASSIC="Classic";
9 | }
10 |
--------------------------------------------------------------------------------
/android/src/main/java/com/lmy/smartrefreshlayout/RCTSpinnerStyleModule.java:
--------------------------------------------------------------------------------
1 | package com.lmy.smartrefreshlayout;
2 |
3 | import com.facebook.react.bridge.ReactApplicationContext;
4 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
5 | import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
6 |
7 | import java.util.Collections;
8 | import java.util.HashMap;
9 | import java.util.Map;
10 |
11 | import javax.annotation.Nullable;
12 |
13 | /**
14 | * Created by macbook on 2018/6/13.
15 | */
16 |
17 | public class RCTSpinnerStyleModule extends ReactContextBaseJavaModule {
18 | private static final String MODULE_NAME = "RCTSpinnerStyleModule";
19 |
20 | public RCTSpinnerStyleModule(ReactApplicationContext reactContext) {
21 | super(reactContext);
22 | }
23 |
24 | @Override
25 | public String getName() {
26 | return MODULE_NAME;
27 | }
28 |
29 | /**
30 | *
31 | *Translate,//平行移动 特点: HeaderView高度不会改变,
32 | *Scale,//拉伸形变 特点:在下拉和上弹(HeaderView高度改变)时候,会自动触发OnDraw事件
33 | *FixedBehind,//固定在背后 特点:HeaderView高度不会改变,
34 | *FixedFront,//固定在前面 特点:HeaderView高度不会改变,
35 | *MatchLayout//填满布局
36 | *
37 | * @return
38 | */
39 | @Nullable
40 | @Override
41 | public Map getConstants() {
42 | return Collections.unmodifiableMap(new HashMap(){{
43 | put("translate", SpinnerStyleConstants.TRANSLATE);
44 | put("fixBehind",SpinnerStyleConstants.FIX_BEHIND);
45 | put("fixFront",SpinnerStyleConstants.FIX_FRONT);
46 | put("scale",SpinnerStyleConstants.SCALE);
47 | put("matchLayout",SpinnerStyleConstants.MATCH_LAYOUT);
48 | }});
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/android/src/main/java/com/lmy/smartrefreshlayout/ReactSmartRefreshLayout.java:
--------------------------------------------------------------------------------
1 | package com.lmy.smartrefreshlayout;
2 |
3 | import android.content.Context;
4 | import android.view.MotionEvent;
5 |
6 | import com.facebook.react.uimanager.events.NativeGestureUtil;
7 | import com.scwang.smartrefresh.layout.SmartRefreshLayout;
8 |
9 | /**
10 | * Created by painter.g on 2018/3/7.
11 | */
12 |
13 | public class ReactSmartRefreshLayout extends SmartRefreshLayout {
14 | private static final float DEFAULT_CIRCLE_TARGET = 64;
15 |
16 | private boolean mDidLayout = false;
17 | private boolean mRefreshing = false;
18 | private float mProgressViewOffset = 0;
19 | private int mTouchSlop;
20 | private float mPrevTouchX;
21 | private boolean mIntercepted;
22 | public ReactSmartRefreshLayout(Context context) {
23 | super(context);
24 | }
25 | @Override
26 | public void onLayout(boolean changed, int left, int top, int right, int bottom) {
27 | super.onLayout(changed, left, top, right, bottom);
28 |
29 | if (!mDidLayout) {
30 | mDidLayout = true;
31 |
32 | // Update values that must be set after initial layout.
33 | // setProgressViewOffset(mProgressViewOffset);
34 | // setRefreshing(mRefreshing);
35 | }
36 | }
37 |
38 |
39 | @Override
40 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
41 | if (getParent() != null) {
42 | getParent().requestDisallowInterceptTouchEvent(disallowIntercept);
43 | }
44 | }
45 |
46 | @Override
47 | public boolean onInterceptTouchEvent(MotionEvent ev) {
48 | if (shouldInterceptTouchEvent(ev) && super.onInterceptTouchEvent(ev)) {
49 | NativeGestureUtil.notifyNativeGestureStarted(this, ev);
50 | return true;
51 | }
52 | return false;
53 | }
54 |
55 |
56 | private boolean shouldInterceptTouchEvent(MotionEvent ev) {
57 | switch (ev.getAction()) {
58 | case MotionEvent.ACTION_DOWN:
59 | mPrevTouchX = ev.getX();
60 | mIntercepted = false;
61 | break;
62 |
63 | case MotionEvent.ACTION_MOVE:
64 | final float eventX = ev.getX();
65 | final float xDiff = Math.abs(eventX - mPrevTouchX);
66 |
67 | if (mIntercepted || xDiff > mTouchSlop) {
68 | mIntercepted = true;
69 | return false;
70 | }
71 | }
72 | return true;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/android/src/main/java/com/lmy/smartrefreshlayout/SmartRefreshLayoutManager.java:
--------------------------------------------------------------------------------
1 | package com.lmy.smartrefreshlayout;
2 |
3 | import android.graphics.Color;
4 | import android.view.View;
5 |
6 | import com.facebook.react.bridge.Arguments;
7 | import com.facebook.react.bridge.ReadableArray;
8 | import com.facebook.react.bridge.ReadableMap;
9 | import com.facebook.react.bridge.WritableMap;
10 | import com.facebook.react.common.MapBuilder;
11 | import com.facebook.react.uimanager.ThemedReactContext;
12 | import com.facebook.react.uimanager.ViewGroupManager;
13 | import com.facebook.react.uimanager.annotations.ReactProp;
14 | import com.facebook.react.uimanager.events.RCTEventEmitter;
15 | import com.lmy.header.AnyHeader;
16 | import com.scwang.smartrefresh.layout.api.RefreshFooter;
17 | import com.scwang.smartrefresh.layout.api.RefreshHeader;
18 | import com.scwang.smartrefresh.layout.api.RefreshLayout;
19 | import com.scwang.smartrefresh.layout.constant.RefreshState;
20 | import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
21 | import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener;
22 | import com.scwang.smartrefresh.layout.util.DensityUtil;
23 |
24 | import java.util.List;
25 | import java.util.Map;
26 |
27 | import javax.annotation.Nullable;
28 |
29 | /**
30 | * Created by painter.g on 2018/3/6.
31 | * SmartRefreshLayout插件的封装
32 | * https://github.com/scwang90/SmartRefreshLayout
33 | */
34 |
35 | public class SmartRefreshLayoutManager extends ViewGroupManager{
36 | //返回给rn的组件名
37 | protected static final String REACT_CLASS="SmartRefreshLayout";
38 |
39 | private ReactSmartRefreshLayout smartRefreshLayout;
40 | private RCTEventEmitter mEventEmitter;
41 | private ThemedReactContext themedReactContext;
42 |
43 | private static final String COMMAND_FINISH_REFRESH_NAME="finishRefresh";
44 | private static final int COMMAND_FINISH_REFRESH_ID=0;
45 |
46 | @Override
47 | public String getName() {
48 | return REACT_CLASS;
49 | }
50 |
51 | @Override
52 | protected ReactSmartRefreshLayout createViewInstance(ThemedReactContext reactContext) {
53 | smartRefreshLayout=new ReactSmartRefreshLayout(reactContext);
54 | smartRefreshLayout.setEnableLoadMore(false);//暂时禁止上拉加载
55 | themedReactContext=reactContext;
56 | mEventEmitter=reactContext.getJSModule(RCTEventEmitter.class);
57 | return smartRefreshLayout;
58 | }
59 |
60 | @Override
61 | public Map getExportedCustomDirectEventTypeConstants() {
62 | MapBuilder.Builder builder = MapBuilder.builder();
63 | for (Events event : Events.values()) {
64 | builder.put(event.toString(), MapBuilder.of("registrationName", event.toString()));
65 | }
66 | return builder.build();
67 | }
68 |
69 | @Nullable
70 | @Override
71 | public Map getCommandsMap() {
72 | return MapBuilder.of(
73 | COMMAND_FINISH_REFRESH_NAME,COMMAND_FINISH_REFRESH_ID
74 | );
75 | }
76 | /**
77 | * 最大显示下拉高度/Header标准高度
78 | * @param view
79 | * @param maxDragRate
80 | */
81 | @ReactProp(name="maxDragRate",defaultFloat = 2.0f)
82 | public void setMaxDragRate(ReactSmartRefreshLayout view,float maxDragRate){
83 | view.setHeaderMaxDragRate(maxDragRate);
84 | }
85 | /**
86 | * 显示下拉高度/手指真实下拉高度=阻尼效果
87 | * @param view
88 | * @param dragRate
89 | */
90 | @ReactProp(name = "dragRate",defaultFloat = 0.5f)
91 | public void setDragRate(ReactSmartRefreshLayout view,float dragRate){
92 | view.setDragRate(dragRate);
93 | }
94 | /**
95 | * 是否使用越界拖动
96 | * @param view
97 | * @param overScrollDrag
98 | */
99 | @ReactProp(name="overScrollDrag",defaultBoolean = true)
100 | public void setOverScrollDrag(ReactSmartRefreshLayout view,boolean overScrollDrag){
101 | view.setEnableOverScrollDrag(overScrollDrag);
102 | }
103 | /**
104 | * 是否启用越界回弹
105 | * @param view
106 | * @param overScrollBounce
107 | */
108 | @ReactProp(name = "overScrollBounce",defaultBoolean = true)
109 | public void setOverScrollBounce(ReactSmartRefreshLayout view,boolean overScrollBounce){
110 | view.setEnableOverScrollBounce(overScrollBounce);
111 | }
112 | /**
113 | * 设置为纯滚动
114 | * @param view
115 | * @param pureScroll
116 | */
117 | @ReactProp(name = "pureScroll",defaultBoolean = false)
118 | public void setPureScroll(ReactSmartRefreshLayout view,boolean pureScroll){
119 | view.setEnablePureScrollMode(pureScroll);
120 | }
121 | /**
122 | * 通过RefreshLayout设置主题色
123 | * @param view
124 | * @param primaryColor
125 | */
126 | @ReactProp(name = "primaryColor",defaultInt = Color.TRANSPARENT)
127 | public void setPrimaryColor(ReactSmartRefreshLayout view, int primaryColor){
128 | view.setPrimaryColors(primaryColor);
129 | }
130 | /**
131 | * 设置headerHeight
132 | * @param view
133 | * @param headerHeight
134 | */
135 | @ReactProp(name = "headerHeight")
136 | public void setHeaderHeight(ReactSmartRefreshLayout view,float headerHeight){
137 | if(headerHeight != 0.0f) {
138 | view.setHeaderHeight(headerHeight);
139 |
140 | }
141 | }
142 | /**
143 | * 是否启用下拉刷新功能
144 | * @param view
145 | * @param enableRefresh
146 | */
147 | @ReactProp(name="enableRefresh",defaultBoolean = true)
148 | public void setEnableRefresh(ReactSmartRefreshLayout view,boolean enableRefresh){
149 | view.setEnableRefresh(enableRefresh);
150 | }
151 |
152 | /**
153 | * 是否启用自动刷新
154 | * @param view
155 | * @param autoRefresh
156 | */
157 | @ReactProp(name = "autoRefresh",defaultBoolean = false)
158 | public void setAutoRefresh(ReactSmartRefreshLayout view, ReadableMap autoRefresh){
159 | boolean isAutoRefresh=false;Integer time=null;
160 | if(autoRefresh.hasKey("refresh")){
161 | isAutoRefresh=autoRefresh.getBoolean("refresh");
162 | }
163 | if(autoRefresh.hasKey("time")){
164 | time=autoRefresh.getInt("time");
165 | }
166 | if(isAutoRefresh==true){
167 | if(time!=null && time>0){
168 | view.autoRefresh(time);
169 | }else{
170 | view.autoRefresh();
171 | }
172 | }
173 | }
174 | @Override
175 | public void receiveCommand(ReactSmartRefreshLayout root, int commandId, @Nullable ReadableArray args) {
176 | switch (commandId){
177 | case COMMAND_FINISH_REFRESH_ID:
178 | int delayed=args.getInt(0);
179 | boolean success=args.getBoolean(1);
180 | if(delayed>=0){
181 | root.finishRefresh(delayed,success);
182 | }else{
183 | root.finishRefresh(success);
184 | }
185 | break;
186 | default:break;
187 | }
188 | }
189 |
190 | @Override
191 | public void addView(ReactSmartRefreshLayout parent, View child, int index) {
192 | switch (index){
193 | case 0:
194 | RefreshHeader header;
195 | if(child instanceof RefreshHeader){
196 | header=(RefreshHeader)child;
197 | }else{
198 | header=new AnyHeader(themedReactContext);
199 | ((AnyHeader)header).setView(child);
200 | }
201 | parent.setRefreshHeader(header);
202 | //parent.setRefreshHeader(new MaterialHeader(themedReactContext).setShowBezierWave(true));
203 | break;
204 | case 1:
205 | parent.setRefreshContent(child);
206 | break;
207 | case 2:
208 | //RefreshFooter footer=(RefreshFooter)child;
209 | //parent.setRefreshFooter(footer);
210 | break;
211 | default:break;
212 |
213 | }
214 | }
215 |
216 | @Override
217 | public void addViews(ReactSmartRefreshLayout parent, List views) {
218 | super.addViews(parent, views);
219 | }
220 |
221 | @Override
222 | protected void addEventEmitters(ThemedReactContext reactContext,final ReactSmartRefreshLayout view) {
223 |
224 |
225 | /**
226 | * 必须设置OnRefreshListener,如果没有设置,
227 | * 则会自动触发finishRefresh
228 | *
229 | * OnRefreshListener和OnSimpleMultiPurposeListener
230 | * 中的onRefresh都会触发刷新,只需写一个即可
231 | */
232 | view.setOnRefreshListener(new OnRefreshListener() {
233 | @Override
234 | public void onRefresh(RefreshLayout refreshLayout) {
235 |
236 | }
237 | });
238 | view.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
239 | private int getTargetId(){
240 | return view.getId();
241 | }
242 |
243 | @Override
244 | public void onHeaderPulling(RefreshHeader header, float percent, int offset, int headerHeight, int extendHeight) {
245 | WritableMap writableMap = Arguments.createMap();
246 | writableMap.putDouble("percent",percent);
247 | writableMap.putDouble("offset",DensityUtil.px2dp(offset));
248 | writableMap.putDouble("headerHeight",DensityUtil.px2dp(headerHeight));
249 | mEventEmitter.receiveEvent(getTargetId(),Events.HEADER_PULLING.toString(),writableMap);
250 | }
251 |
252 | @Override
253 | public void onHeaderReleased(RefreshHeader header, int headerHeight, int extendHeight) {
254 | WritableMap writableMap = Arguments.createMap();
255 | writableMap.putDouble("headerHeight",DensityUtil.px2dp(headerHeight));
256 | mEventEmitter.receiveEvent(getTargetId(),Events.HEADER_RELEASED.toString(),writableMap);
257 | }
258 |
259 | @Override
260 | public void onHeaderReleasing(RefreshHeader header, float percent, int offset, int headerHeight, int extendHeight) {
261 | WritableMap writableMap = Arguments.createMap();
262 | writableMap.putDouble("percent",percent);
263 | writableMap.putDouble("offset",DensityUtil.px2dp(offset));
264 | writableMap.putDouble("headerHeight",DensityUtil.px2dp(headerHeight));
265 | mEventEmitter.receiveEvent(getTargetId(),Events.HEADER_RELEASING.toString(),writableMap);
266 | }
267 |
268 | @Override
269 | public void onFooterPulling(RefreshFooter footer, float percent, int offset, int footerHeight, int extendHeight) {
270 | WritableMap writableMap = Arguments.createMap();
271 | writableMap.putDouble("percent",percent);
272 | writableMap.putDouble("offset",DensityUtil.px2dp(offset));
273 | writableMap.putDouble("footerHeight",DensityUtil.px2dp(footerHeight));
274 | mEventEmitter.receiveEvent(getTargetId(),Events.FOOTER_MOVING.toString(),writableMap);
275 | }
276 |
277 | @Override
278 | public void onFooterReleasing(RefreshFooter footer, float percent, int offset, int footerHeight, int extendHeight) {
279 | WritableMap writableMap = Arguments.createMap();
280 | writableMap.putDouble("percent",percent);
281 | writableMap.putDouble("offset",DensityUtil.px2dp(offset));
282 | writableMap.putDouble("footerHeight",DensityUtil.px2dp(footerHeight));
283 | mEventEmitter.receiveEvent(getTargetId(),Events.FOOTER_MOVING.toString(),writableMap);
284 | }
285 |
286 | @Override
287 | public void onHeaderStartAnimator(RefreshHeader header, int headerHeight, int extendHeight) {
288 |
289 | }
290 |
291 | @Override
292 | public void onHeaderFinish(RefreshHeader header, boolean success) {
293 |
294 | }
295 | @Override
296 | public void onLoadMore(RefreshLayout refreshLayout) {
297 | mEventEmitter.receiveEvent(getTargetId(),Events.LOAD_MORE.toString(),null);
298 | }
299 |
300 | @Override
301 | public void onRefresh(RefreshLayout refreshLayout) {
302 | mEventEmitter.receiveEvent(getTargetId(),Events.REFRESH.toString(),null);
303 | }
304 |
305 | @Override
306 | public void onStateChanged(RefreshLayout refreshLayout, RefreshState oldState, RefreshState newState) {
307 | switch (newState) {
308 | case None:
309 | case PullDownToRefresh:
310 | mEventEmitter.receiveEvent(getTargetId(),Events.PULL_DOWN_TO_REFRESH.toString(),null);
311 | break;
312 | case Refreshing:
313 |
314 | break;
315 | case ReleaseToRefresh:
316 | mEventEmitter.receiveEvent(getTargetId(),Events.RELEASE_TO_REFRESH.toString(),null);
317 | break;
318 | }
319 |
320 | }
321 | });
322 | }
323 | private int getTargetId(){
324 | return smartRefreshLayout.getId();
325 | }
326 | }
327 |
--------------------------------------------------------------------------------
/android/src/main/java/com/lmy/smartrefreshlayout/SmartRefreshLayoutPackage.java:
--------------------------------------------------------------------------------
1 | package com.lmy.smartrefreshlayout;
2 |
3 | import com.facebook.react.ReactPackage;
4 | import com.facebook.react.bridge.JavaScriptModule;
5 | import com.facebook.react.bridge.NativeModule;
6 | import com.facebook.react.bridge.ReactApplicationContext;
7 | import com.facebook.react.uimanager.ViewManager;
8 | import com.lmy.header.AnyHeaderManager;
9 | import com.lmy.header.ClassicsHeaderManager;
10 | import com.lmy.header.DefaultHeaderMananger;
11 | import com.lmy.header.MaterialHeaderManager;
12 | import com.lmy.header.StoreHouseHeaderManager;
13 |
14 | import java.util.Arrays;
15 | import java.util.Collections;
16 | import java.util.List;
17 |
18 | /**
19 | * Created by painter.g on 2018/3/6.
20 | */
21 |
22 | public class SmartRefreshLayoutPackage implements ReactPackage {
23 | @Override
24 | public List createNativeModules(ReactApplicationContext reactContext) {
25 | return Arrays.asList(
26 | new RCTSpinnerStyleModule(reactContext)
27 | );
28 | }
29 | //@Override >=0.47已经过期
30 | public List> createJSModules() {
31 | return Collections.emptyList();
32 | }
33 | @Override
34 | public List createViewManagers(ReactApplicationContext reactContext) {
35 | return Arrays.asList(
36 | new SmartRefreshLayoutManager(),
37 | new ClassicsHeaderManager(),
38 | new StoreHouseHeaderManager(),
39 | new MaterialHeaderManager(),
40 | new AnyHeaderManager(),
41 | new DefaultHeaderMananger()
42 | );
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/android/src/main/java/com/lmy/smartrefreshlayout/SpinnerStyleConstants.java:
--------------------------------------------------------------------------------
1 | package com.lmy.smartrefreshlayout;
2 |
3 | import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
4 |
5 | import java.util.HashMap;
6 |
7 | /**
8 | * Created by macbook on 2018/6/13.
9 | */
10 |
11 | public class SpinnerStyleConstants {
12 | public static final String TRANSLATE = "translate";
13 | public static final String FIX_BEHIND = "fixBehind";
14 | public static final String SCALE = "scale";
15 | public static final String FIX_FRONT = "fixFront";
16 | public static final String MATCH_LAYOUT = "matchLayout";
17 | public static final HashMap SpinnerStyleMap = new HashMap(){{
18 | put(TRANSLATE,SpinnerStyle.Translate);
19 | put(FIX_BEHIND,SpinnerStyle.FixedBehind);
20 | put(SCALE,SpinnerStyle.Scale);
21 | put(MATCH_LAYOUT,SpinnerStyle.MatchLayout);
22 | put(FIX_FRONT,SpinnerStyle.FixedFront);
23 | }};
24 | }
25 |
--------------------------------------------------------------------------------
/android/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/android/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SmartRefreshLayout
3 |
4 |
--------------------------------------------------------------------------------
/android/src/test/java/com/lmy/smartrefreshlayout/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.lmy.smartrefreshlayout;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/docs/AnyHeader.md:
--------------------------------------------------------------------------------
1 | # AnyHeader
2 |
3 | ## 查看属性
4 |
5 | - [`primaryColor`](AnyHeader.md#primarycolor)
6 |
7 |
8 | # 文档
9 |
10 | ## Props
11 |
12 | ### `primaryColor`
13 |
14 | 刷新组件Header的主调色
15 |
16 | | Type | Required |
17 | | ---- | -------- |
18 | | string | No |
--------------------------------------------------------------------------------
/docs/DefaultHeader.md:
--------------------------------------------------------------------------------
1 | # DefaultHeader/ClassicsHeader
2 |
3 | ## 查看属性
4 |
5 | - [`primaryColor`](DefaultHeader.md#primarycolor)
6 | - [`accentColor`](DefaultHeader.md#accentcolor)
7 |
8 |
9 | # 文档
10 |
11 | ## Props
12 |
13 | ### `primaryColor`
14 |
15 | 刷新组件Header的主调色
16 |
17 | | Type | Required |
18 | | ---- | -------- |
19 | | string | No |
20 |
21 | ---
22 |
23 | ### `accentColor`
24 |
25 | 刷新组件Header的强调色
26 |
27 | | Type | Required |
28 | | ---- | -------- |
29 | | string | No |
--------------------------------------------------------------------------------
/docs/StoreHouse.md:
--------------------------------------------------------------------------------
1 | # StoreHouseHeader
2 |
3 | ## 查看属性
4 |
5 | - [`text`](StoreHouse.md#text)
6 | - [`textColor`](StoreHouse.md#textcolor)
7 | - [`lineWitdh`](StoreHouse.md#linewidth)
8 |
9 |
10 | # 文档
11 |
12 | ## Props
13 |
14 | ### `text`
15 |
16 | StoreHouseHeader的文字
17 |
18 | | Type | Required |
19 | | ---- | -------- |
20 | | string | No |
21 |
22 | ---
23 |
24 | ### `textColor`
25 |
26 | StoreHouseHeader的文字颜色
27 |
28 | | Type | Required |
29 | | ---- | -------- |
30 | | string | No |
31 |
32 | ---
33 |
34 | ### `lineWidth`
35 |
36 | StoreHouseHeader的文字线宽
37 |
38 | | Type | Required |
39 | | ---- | -------- |
40 | | number | No |
--------------------------------------------------------------------------------
/images/Screenshot_1520489593.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/images/Screenshot_1520489593.png
--------------------------------------------------------------------------------
/images/Screenshot_1520489605.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/images/Screenshot_1520489605.png
--------------------------------------------------------------------------------
/images/lottierefresh.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/react-native-studio/react-native-SmartRefreshLayout/c14a234a4b57b42433cb08a85a6366e8b46b09e5/images/lottierefresh.gif
--------------------------------------------------------------------------------
/index.d.ts:
--------------------------------------------------------------------------------
1 | import react, { Component } from "react"
2 | import {ViewProps} from "react-native";
3 | interface SmartRefreshLayoutProps extends ViewProps{
4 | onRefresh?:()=>void,
5 | onHeaderPulling?:(p: RefreshEvent)=>void,
6 | onHeaderReleasing?:(p: RefreshEvent)=>void,
7 | onHeaderMoving?:(p: RefreshEvent)=>void,//向外提供的接口
8 | onPullDownToRefresh?:()=>void,
9 | onReleaseToRefresh?:()=>void,
10 | onHeaderReleased?:()=>void,
11 | enableRefresh?:boolean,//是否启用下拉刷新功能
12 | renderHeader?:()=>React.ReactElement | React.ReactElement,
13 | headerHeight?:number,
14 | overScrollBounce?:boolean,//是否使用越界回弹
15 | overScrollDrag?:boolean,//是否使用越界拖动,类似IOS样式
16 | pureScroll?:boolean,//是否使用纯滚动模式
17 | dragRate?:number,// 显示下拉高度/手指真实下拉高度=阻尼效果
18 | maxDragRate?:number,//最大显示下拉高度/Header标准高度
19 | primaryColor?:string,
20 | autoRefresh?: AutoRefresh,//是否启动自动刷新
21 | }
22 | type RefreshEvent = {
23 | nativeEvent: RefreshNativeEvent
24 | }
25 | type RefreshNativeEvent = { percent: number, offset:number, headerHeight: number}
26 | type AutoRefresh = { refresh?:boolean,time?:number }
27 | type FinishRefreshParams = { delayed?: number, success?:boolean}
28 | export class SmartRefreshLayout extends Component{
29 | finishRefresh:(params?:FinishRefreshParams)=>void
30 | }
31 |
32 | interface ClassicsHeaderProps extends ViewProps{
33 | primaryColor?: string,
34 | accentColor?: string,
35 | }
36 | export class ClassicsHeader extends Component{}
37 |
38 | interface DefaultHeaderProps extends ClassicsHeaderProps{}
39 | export class DefaultHeader extends Component{}
40 |
41 | interface StoreHouseHeaderProps extends ViewProps{
42 | textColor?: string,
43 | text?: string,//暂时只支持英文
44 | fontSize?: number,
45 | lineWidth?: number,
46 | dropHeight?: number,
47 | }
48 | export class StoreHouseHeader extends Component{}
49 |
50 | interface AnyHeaderProps extends ViewProps{}
51 | export class AnyHeader extends Component{}
52 |
53 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | export {default as SmartRefreshControl} from './SmartRefreshControl';
2 | export {default as ClassicsHeader} from './ClassicsHeader';
3 | export {default as StoreHouseHeader} from './StoreHouseHeader';
4 | export {default as DefaultHeader} from './DefaultHeader';
5 | export {default as AnyHeader} from './AnyHeader';
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-smartrefreshlayout",
3 | "version": "0.6.7",
4 | "description": "基于android SmartRefreshLayout的封装",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "npm test"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/react-native-studio/react-native-SmartRefreshLayout.git"
12 | },
13 | "keywords": [
14 | "react",
15 | "react",
16 | "native",
17 | "pull",
18 | "refresh",
19 | "refreshcontrol",
20 | "refreshlayout"
21 | ],
22 | "author": "react-native-studio",
23 | "license": "ISC",
24 | "bugs": {
25 | "url": "https://github.com/react-native-studio/react-native-SmartRefreshLayout/issues"
26 | },
27 | "homepage": "https://github.com/react-native-studio/react-native-SmartRefreshLayout#readme",
28 | "dependencies": {
29 | "prop-types":"*"
30 | }
31 | }
32 |
33 |
--------------------------------------------------------------------------------