Skip to content

fixes for react 26+ #62

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ControlledRefreshableListView.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var ControlledRefreshableListView = require('./lib/ControlledRefreshableListView')
var {DataSource} = require('./lib/ListView')
var RefreshingIndicator = require('./lib/RefreshingIndicator')
import ControlledRefreshableListView from './lib/ControlledRefreshableListView';
import {DataSource} from './lib/ListView';
import RefreshingIndicator from './lib/RefreshingIndicator';

Object.assign(ControlledRefreshableListView, {
DataSource,
RefreshingIndicator,
})
});

module.exports = ControlledRefreshableListView
export default ControlledRefreshableListView;
12 changes: 6 additions & 6 deletions RefreshableListView.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var RefreshableListView = require('./lib/RefreshableListView')
var ControlledRefreshableListView = require('./ControlledRefreshableListView')
var {DataSource} = require('./lib/ListView')
var RefreshingIndicator = require('./lib/RefreshingIndicator')
import RefreshableListView from './lib/RefreshableListView';
import ControlledRefreshableListView from './ControlledRefreshableListView';
import {DataSource} from './lib/ListView';
import RefreshingIndicator from './lib/RefreshingIndicator';

Object.assign(RefreshableListView, {
DataSource,
RefreshingIndicator,
ControlledRefreshableListView,
})
});

module.exports = RefreshableListView
export default RefreshableListView;
3 changes: 2 additions & 1 deletion RefreshingIndicator.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = require('./lib/RefreshingIndicator')
import RefreshingIndicator from './lib/RefreshingIndicator';
export default RefreshingIndicator;
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = require('./RefreshableListView')
import RefreshableListView from './lib/RefreshableListView';
export default RefreshableListView;
113 changes: 62 additions & 51 deletions lib/ControlledRefreshableListView.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
var React = require('react-native')
var {
PropTypes,
import React, { Component, PropTypes } from 'react';
import {
StyleSheet,
View,
Platform,
PullToRefreshViewAndroid,
} = React
var ListView = require('./ListView')
var createElementFrom = require('./createElementFrom')
var RefreshingIndicator = require('./RefreshingIndicator')
var scrollToCompat = require('./scrollToCompat')
RefreshControl,
} from 'react-native';
import ListView from './ListView';
import createElementFrom from './createElementFrom';
import RefreshingIndicator from './RefreshingIndicator';
import scrollToCompat from './scrollToCompat';

const SCROLL_EVENT_THROTTLE = 32
const MIN_PULLDOWN_DISTANCE = 40
Expand All @@ -27,8 +26,8 @@ const LISTVIEW_REF = 'listview'
* {isRefreshing: false}
*/

var ControlledRefreshableListView = React.createClass({
propTypes: {
export default class ControlledRefreshableListView extends Component {
static propTypes = {
colors: PropTypes.array,
progressBackgroundColor: PropTypes.string,
onRefresh: PropTypes.func.isRequired,
Expand Down Expand Up @@ -60,28 +59,27 @@ var ControlledRefreshableListView = React.createClass({
return new Error('The \'refreshingIndictatorComponent\' prop has been renamed to \'refreshingIndicatorComponent\'')
}
},
},
getDefaultProps() {
return {
}

static defaultProps = {
minPulldownDistance: MIN_PULLDOWN_DISTANCE,
scrollEventThrottle: SCROLL_EVENT_THROTTLE,
ignoreInertialScroll: true,
refreshingIndicatorComponent: RefreshingIndicator,
pullingPrompt: 'Pull to refresh',
holdingPrompt: 'Release to refresh',
}
},
getInitialState() {
return {
waitingForRelease: false,
}
},
}
state = {
waitingForRelease: false
}

componentWillReceiveProps(nextProps) {
if (!this.props.isRefreshing && nextProps.isRefreshing && this.isTouching) {
this.waitingForRelease = true
this.setState({waitingForRelease: true})
}
},
}

componentWillUpdate(nextProps, nextState) {
if (Platform.OS === 'ios') {
if (
Expand All @@ -95,7 +93,8 @@ var ControlledRefreshableListView = React.createClass({
)
}
}
},
}

componentDidUpdate(prevProps, prevState) {
if (Platform.OS === 'ios') {
if (
Expand All @@ -109,12 +108,14 @@ var ControlledRefreshableListView = React.createClass({
)
}
}
},
handlePullToRefreshViewAndroidRef(swipeRefreshLayout) {
}

handleRefreshControlRef(swipeRefreshLayout) {
this.swipeRefreshLayout = swipeRefreshLayout
},
}

handleScroll(e) {
var scrollY = e.nativeEvent.contentInset.top + e.nativeEvent.contentOffset.y
const scrollY = e.nativeEvent.contentInset.top + e.nativeEvent.contentOffset.y
this.lastScrollY = scrollY
this.lastContentInsetTop = e.nativeEvent.contentInset.top
this.lastContentOffsetX = e.nativeEvent.contentOffset.x
Expand All @@ -138,13 +139,15 @@ var ControlledRefreshableListView = React.createClass({
}

this.props.onScroll && this.props.onScroll(e)
},
}

handleResponderGrant() {
this.isTouching = true
if (this.props.onResponderGrant) {
this.props.onResponderGrant.apply(null, arguments)
}
},
}

handleResponderRelease() {
this.isTouching = false
if (this.props.onResponderRelease) {
Expand All @@ -160,29 +163,35 @@ var ControlledRefreshableListView = React.createClass({
}
}
this.props.onPull()
},
}

getContentContainerStyle() {
if (!this.props.isRefreshing || this.isWaitingForRelease()) return null

return {marginTop: REFRESHING_INDICATOR_HEIGHT}
},
}

getScrollResponder() {
return this.refs[LISTVIEW_REF].getScrollResponder()
},
}

setNativeProps(props) {
this.refs[LISTVIEW_REF].setNativeProps(props)
},
}

isWaitingForRelease() {
return this.waitingForRelease || this.props.waitingForRelease
},
}

isReleaseUpdate(oldProps, oldState, newProps, newState) {
return (
(!oldProps.isRefreshing && newProps.isRefreshing && !this.waitingForRelease) ||
(oldProps.isRefreshing && oldState.waitingForRelease && !newState.waitingForRelease)
)
},
}

renderRefreshingIndicator() {
var {
const {
isRefreshing,
pullingPrompt,
holdingPrompt,
Expand All @@ -192,7 +201,7 @@ var ControlledRefreshableListView = React.createClass({
holdingIndicator,
refreshingIndicator,
} = this.props
var refreshingIndicatorProps = {
const refreshingIndicatorProps = {
isRefreshing,
pullingIndicator,
holdingIndicator,
Expand All @@ -204,22 +213,25 @@ var ControlledRefreshableListView = React.createClass({
isWaitingForRelease: this.isWaitingForRelease(),
}
return createElementFrom(this.props.refreshingIndicatorComponent, refreshingIndicatorProps)
},
}

render() {
if (Platform.OS === 'android') {
return (
<PullToRefreshViewAndroid
ref={this.handlePullToRefreshViewAndroidRef}
<RefreshControl
ref={this.handleRefreshControlRef}
onRefresh={this.props.onRefresh}
refreshing={this.props.isRefreshing}
colors={this.props.colors}
progressBackgroundColor={this.props.progressBackgroundColor}
style={stylesheet.container}
>
<ListView
{...this.props}
ref={LISTVIEW_REF}
enableEmptySections={true}
/>
</PullToRefreshViewAndroid>
</RefreshControl>
)
} else {
return (
Expand All @@ -231,20 +243,21 @@ var ControlledRefreshableListView = React.createClass({
<ListView
{...this.props}
ref={LISTVIEW_REF}
contentContainerStyle={this.getContentContainerStyle()}
onScroll={this.handleScroll}
contentContainerStyle={[this.getContentContainerStyle(), this.props.contentContainerStyle]}
onScroll={this.handleScroll.bind(this)}
scrollEventThrottle={this.props.scrollEventThrottle}
onResponderGrant={this.handleResponderGrant}
onResponderRelease={this.handleResponderRelease}
onResponderGrant={this.handleResponderGrant.bind(this)}
onResponderRelease={this.handleResponderRelease.bind(this)}
enableEmptySections={true}
/>
</View>
</View>
)
}
},
})
}
}

var stylesheet = StyleSheet.create({
const stylesheet = StyleSheet.create({
container: {
flex: 1,
},
Expand All @@ -256,6 +269,4 @@ var stylesheet = StyleSheet.create({
right: 0,
bottom: 0,
},
})

module.exports = ControlledRefreshableListView
})
5 changes: 2 additions & 3 deletions lib/ListView.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
var {ListView} = require('react-native')

module.exports = ListView
import { ListView } from 'react-native';
export default ListView;
Loading