Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed https://github.com/gameboyVito/react-native-ultimate-listview/issues/34 #67

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-ultimate-listview",
"version": "3.3.0",
"name": "@bang88/react-native-ultimate-listview",
"version": "4.1.0",
"description": "A high performance FlatList providing customised pull-to-refresh | auto-pagination & infinite-scrolling | gridview layout | swipeable-row. The truly ultimate version that I have done the most tricky part for you, just simply follow the instructions shown below to put it in your app.",
"main": "index.js",
"scripts": {
Expand Down
35 changes: 8 additions & 27 deletions src/refreshableScrollView.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react'
import {
ActivityIndicator,
Animated,
AsyncStorage,
Dimensions,
Easing,
ScrollView,
Expand All @@ -13,7 +12,6 @@ import {
import dateFormat from './util'

const { width, height } = Dimensions.get('window')
const DATE_KEY = 'ultimateRefreshDate'
const RefreshStatus = {
pullToRefresh: 0,
releaseToRefresh: 1,
Expand All @@ -25,7 +23,7 @@ const PaginationStatus = {
allLoaded: 2
}

export default class RefreshableScrollView extends ScrollView {
export default class RefreshableScrollView extends React.Component {
static defaultProps = {
horizontal: false,
scrollEnabled: true,
Expand Down Expand Up @@ -61,25 +59,6 @@ export default class RefreshableScrollView extends ScrollView {
}
}

async componentDidMount() {
console.warn('The advancedRefreshView is not ready for Android at this moment. \n\nIf the items are less than the height of device screen, the refreshView will not disappear. \n\nPlease consider setting the refreshableMode={Platform.OS === "ios" ? "advanced" : "basic"}, or feel free to send me a PR to resolve this problem. \n\nThanks a lot.')
try {
let result = await AsyncStorage.getItem(DATE_KEY)
if (result) {
result = parseInt(result, 10)
this.setState({
date: dateFormat(new Date(result), this.props.dateFormat)
})
} else {
this.setState({
date: dateFormat(new Date(), this.props.dateFormat)
})
}
} catch (err) {
console.log(err)
}
}

onScroll = (event) => {
// console.log('onScroll()');
const { y } = event.nativeEvent.contentOffset
Expand All @@ -98,7 +77,8 @@ export default class RefreshableScrollView extends ScrollView {
Animated.timing(this.state.arrowAngle, {
toValue: 1,
duration: 50,
easing: Easing.inOut(Easing.quad)
easing: Easing.inOut(Easing.quad),
useNativeDriver: true,
}).start()
}
} else if (this.state.refreshStatus !== RefreshStatus.pullToRefresh) {
Expand All @@ -109,7 +89,8 @@ export default class RefreshableScrollView extends ScrollView {
Animated.timing(this.state.arrowAngle, {
toValue: 0,
duration: 50,
easing: Easing.inOut(Easing.quad)
easing: Easing.inOut(Easing.quad),
useNativeDriver: true,
}).start()
}
}
Expand Down Expand Up @@ -190,11 +171,11 @@ export default class RefreshableScrollView extends ScrollView {
})
}, 1000)

AsyncStorage.setItem(DATE_KEY, now.toString())
Animated.timing(this.state.arrowAngle, {
toValue: 0,
duration: 50,
easing: Easing.inOut(Easing.quad)
easing: Easing.inOut(Easing.quad),
useNativeDriver: true,
}).start()
}
}
Expand All @@ -216,7 +197,7 @@ export default class RefreshableScrollView extends ScrollView {
{this.renderSpinner()}
<Text style={defaultHeaderStyles.statusTitle}>{this.state.refreshTitle}</Text>
</View>
{this.props.displayDate &&
{this.props.displayDate && this.state.date &&
<Text
style={[defaultHeaderStyles.date, this.props.dateStyle]}
>{this.props.dateTitle + this.state.date}
Expand Down
37 changes: 11 additions & 26 deletions src/refreshableScrollView.ios.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react'
import { ActivityIndicator, Animated, AsyncStorage, Easing, ScrollView, StyleSheet, Text, View } from 'react-native'
import { ActivityIndicator, Animated, Easing, ScrollView, StyleSheet, Text, View } from 'react-native'

import dateFormat from './util'

const DATE_KEY = 'ultimateRefreshDate'
const RefreshStatus = {
pullToRefresh: 0,
releaseToRefresh: 1,
Expand All @@ -14,7 +14,7 @@ const PaginationStatus = {
allLoaded: 2
}

export default class RefreshableScrollView extends ScrollView {
export default class RefreshableScrollView extends React.Component {
static defaultProps = {
horizontal: false,
scrollEnabled: true,
Expand Down Expand Up @@ -49,24 +49,6 @@ export default class RefreshableScrollView extends ScrollView {
}
}

async componentDidMount() {
try {
let result = await AsyncStorage.getItem(DATE_KEY)
if (result) {
result = parseInt(result, 10)
this.setState({
date: dateFormat(new Date(result), this.props.dateFormat)
})
} else {
this.setState({
date: dateFormat(new Date(), this.props.dateFormat)
})
}
} catch (err) {
console.log(err)
}
}

onScroll = (event) => {
// console.log('onScroll()');
const { y } = event.nativeEvent.contentOffset
Expand All @@ -82,7 +64,8 @@ export default class RefreshableScrollView extends ScrollView {
Animated.timing(this.state.arrowAngle, {
toValue: 1,
duration: 50,
easing: Easing.inOut(Easing.quad)
easing: Easing.inOut(Easing.quad),
useNativeDriver: true,
}).start()
} else {
this.setState({
Expand All @@ -92,7 +75,8 @@ export default class RefreshableScrollView extends ScrollView {
Animated.timing(this.state.arrowAngle, {
toValue: 0,
duration: 50,
easing: Easing.inOut(Easing.quad)
easing: Easing.inOut(Easing.quad),
useNativeDriver: true,
}).start()
}
}
Expand Down Expand Up @@ -159,11 +143,11 @@ export default class RefreshableScrollView extends ScrollView {
refreshTitle: this.props.refreshableTitlePull,
date: dateFormat(now, this.props.dateFormat)
})
AsyncStorage.setItem(DATE_KEY, now.toString())
Animated.timing(this.state.arrowAngle, {
toValue: 0,
duration: 50,
easing: Easing.inOut(Easing.quad)
easing: Easing.inOut(Easing.quad),
useNativeDriver: true,
}).start()
this._scrollview.scrollTo({ x: 0, y: 0, animated: true })
}
Expand All @@ -184,7 +168,7 @@ export default class RefreshableScrollView extends ScrollView {
{this.renderSpinner()}
<Text style={defaultHeaderStyles.statusTitle}>{this.state.refreshTitle}</Text>
</View>
{this.props.displayDate &&
{this.props.displayDate && this.state.date &&
<Text style={[defaultHeaderStyles.date, this.props.dateStyle]}>{this.props.dateTitle + this.state.date}</Text>
}
</View>
Expand Down Expand Up @@ -224,6 +208,7 @@ export default class RefreshableScrollView extends ScrollView {
onScroll={this.onScroll}
onScrollEndDrag={this.onScrollEndDrag}
onScrollBeginDrag={this.onScrollBeginDrag}
contentInset={{ top: 80 }}
>
{this.renderRefreshHeader()}
{this.props.children}
Expand Down
Loading