-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
[createReactClass] remove createReactClass from ScrollViewTestModule.js #21627
Closed
sopranolinist
wants to merge
4
commits into
facebook:master
from
sopranolinist:pr/issue-21581-scrollviewtestmodule
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,21 +9,20 @@ | |
|
||
'use strict'; | ||
|
||
var BatchedBridge = require('BatchedBridge'); | ||
var React = require('React'); | ||
var createReactClass = require('create-react-class'); | ||
var View = require('View'); | ||
var ScrollView = require('ScrollView'); | ||
var Text = require('Text'); | ||
var StyleSheet = require('StyleSheet'); | ||
var TouchableWithoutFeedback = require('TouchableWithoutFeedback'); | ||
var ScrollListener = require('NativeModules').ScrollListener; | ||
|
||
var NUM_ITEMS = 100; | ||
const BatchedBridge = require('BatchedBridge'); | ||
const React = require('React'); | ||
const View = require('View'); | ||
const ScrollView = require('ScrollView'); | ||
const Text = require('Text'); | ||
const StyleSheet = require('StyleSheet'); | ||
const TouchableWithoutFeedback = require('TouchableWithoutFeedback'); | ||
const ScrollListener = require('NativeModules').ScrollListener; | ||
|
||
const NUM_ITEMS = 100; | ||
|
||
// Shared by integration tests for ScrollView and HorizontalScrollView | ||
|
||
var scrollViewApp; | ||
let scrollViewApp; | ||
|
||
class Item extends React.Component { | ||
render() { | ||
|
@@ -37,7 +36,7 @@ class Item extends React.Component { | |
} | ||
} | ||
|
||
var getInitialState = function() { | ||
const getInitialState = function() { | ||
var data = []; | ||
for (var i = 0; i < NUM_ITEMS; i++) { | ||
data[i] = {text: 'Item ' + i + '!'}; | ||
|
@@ -47,90 +46,84 @@ var getInitialState = function() { | |
}; | ||
}; | ||
|
||
var onScroll = function(e) { | ||
const onScroll = function(e) { | ||
ScrollListener.onScroll( | ||
e.nativeEvent.contentOffset.x, | ||
e.nativeEvent.contentOffset.y, | ||
); | ||
}; | ||
|
||
var onScrollBeginDrag = function(e) { | ||
const onScrollBeginDrag = function(e) { | ||
ScrollListener.onScrollBeginDrag( | ||
e.nativeEvent.contentOffset.x, | ||
e.nativeEvent.contentOffset.y, | ||
); | ||
}; | ||
|
||
var onScrollEndDrag = function(e) { | ||
const onScrollEndDrag = function(e) { | ||
ScrollListener.onScrollEndDrag( | ||
e.nativeEvent.contentOffset.x, | ||
e.nativeEvent.contentOffset.y, | ||
); | ||
}; | ||
|
||
var onItemPress = function(itemNumber) { | ||
const onItemPress = function(itemNumber) { | ||
ScrollListener.onItemPress(itemNumber); | ||
}; | ||
|
||
var ScrollViewTestApp = createReactClass({ | ||
displayName: 'ScrollViewTestApp', | ||
getInitialState: getInitialState, | ||
onScroll: onScroll, | ||
onItemPress: onItemPress, | ||
onScrollBeginDrag: onScrollBeginDrag, | ||
onScrollEndDrag: onScrollEndDrag, | ||
class ScrollViewTestApp extends React.Component { | ||
scrollView = React.createRef(); | ||
state = getInitialState(); | ||
|
||
scrollTo: function(destX, destY) { | ||
this.refs.scrollView.scrollTo(destY, destX); | ||
}, | ||
scrollTo = (destX, destY) => { | ||
this.scrollView.scrollTo(destY, destX); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should have caught this earlier, but when you create a ref using const { scrollView: { current: scrollView } } = this;
if (scrollView == null) {
return;
}
scrollView.scrollTo(destY, destX); But don't worry about it. 😄 I'll make the fix on my end. |
||
}; | ||
|
||
render: function() { | ||
render() { | ||
scrollViewApp = this; | ||
var children = this.state.data.map((item, index) => ( | ||
<Item | ||
key={index} | ||
text={item.text} | ||
onPress={this.onItemPress.bind(this, index)} | ||
onPress={onItemPress.bind(this, index)} | ||
/> | ||
)); | ||
return ( | ||
<ScrollView | ||
onScroll={this.onScroll} | ||
onScrollBeginDrag={this.onScrollBeginDrag} | ||
onScrollEndDrag={this.onScrollEndDrag} | ||
ref="scrollView"> | ||
onScroll={onScroll} | ||
onScrollBeginDrag={onScrollBeginDrag} | ||
onScrollEndDrag={onScrollEndDrag} | ||
ref={this.scrollView}> | ||
{children} | ||
</ScrollView> | ||
); | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
var HorizontalScrollViewTestApp = createReactClass({ | ||
displayName: 'HorizontalScrollViewTestApp', | ||
getInitialState: getInitialState, | ||
onScroll: onScroll, | ||
onItemPress: onItemPress, | ||
class HorizontalScrollViewTestApp extends React.Component { | ||
scrollView = React.createRef(); | ||
state = getInitialState(); | ||
|
||
scrollTo: function(destX, destY) { | ||
this.refs.scrollView.scrollTo(destY, destX); | ||
}, | ||
scrollTo = (destX, destY) => { | ||
this.scrollView.scrollTo(destY, destX); | ||
}; | ||
|
||
render: function() { | ||
render() { | ||
scrollViewApp = this; | ||
var children = this.state.data.map((item, index) => ( | ||
<Item | ||
key={index} | ||
text={item.text} | ||
onPress={this.onItemPress.bind(this, index)} | ||
onPress={onItemPress.bind(this, index)} | ||
/> | ||
)); | ||
return ( | ||
<ScrollView horizontal={true} onScroll={this.onScroll} ref="scrollView"> | ||
<ScrollView horizontal={true} onScroll={onScroll} ref={this.scrollView}> | ||
{children} | ||
</ScrollView> | ||
); | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
var styles = StyleSheet.create({ | ||
item_container: { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Classes that extend
React.Component
do not callgetInitialState
to get their initial state. With the current configuration,this.state
will benull
inside therender()
method, which will raise an exception given the current implementation of that method. Instead of implementinggetInitialState
, you should create the state and assign it tothis.state
inside the constructor. Since we support class property assignment, we should just do this: