-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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 CameraRollView #21619
Conversation
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.
Looks mostly good, but we have a few problems with our flow types.
RNTester/js/CameraRollView.js
Outdated
|
||
_fetch: async function(clear?: boolean) { | ||
_fetch = async (clear?: boolean) => { |
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.
This doesn't need to be bound:
async _fetch(clear?: boolean) {
RNTester/js/CameraRollView.js
Outdated
|
||
/** | ||
* A function that takes a single image as a parameter and renders it. | ||
*/ | ||
renderImage: PropTypes.func, | ||
renderImage: $FlowFixMe => React.Node, |
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.
this._fetch
calls CameraRoll.getPhotos
and then calls this._appendAssets
after waiting for the CameraRoll.getPhotos
promise to resolve. this._appendAssets
groups the result into rows, and passes the rows to the data source this._ds
. This eventually calls this._renderRow
, which calls this._renderImage
. So, we can actually figure out what this type is, and remove this $FlowFixMe
.
CameraRoll.getPhotos
contains the type information. (I think we should export it, if necessary).
RNTester/js/CameraRollView.js
Outdated
rowID: string, | ||
) { | ||
var images = rowData.map(image => { | ||
_renderRow = (rowData: Array<Image>, sectionID: string, rowID: string) => { |
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.
rowData
isn't an array of Image
components.
RNTester/js/CameraRollView.js
Outdated
|
||
_rowHasChanged: function(r1: Array<Image>, r2: Array<Image>): boolean { | ||
_rowHasChanged(r1: Array<Image>, r2: Array<Image>): boolean { |
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.
This shouldn't be image. 😞
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.
Also, this doesn't have to be a method on the component class.
RNTester/js/CameraRollView.js
Outdated
var newState: Object = {loadingMore: false}; | ||
_appendAssets = (data: Object) => { | ||
const assets = data.edges; | ||
const newState: Object = {loadingMore: false}; |
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.
const newState: $Shape<State> = { loadingMore: false };
RNTester/js/CameraRollView.js
Outdated
import type {RNTesterProps} from 'RNTesterTypes'; | ||
|
||
type Props = $ReadOnly<{| | ||
...RNTesterProps, |
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.
How come you're spreading the RNTesterProps
into Props
?
RNTester/js/CameraRollView.js
Outdated
_appendAssets: function(data: Object) { | ||
var assets = data.edges; | ||
var newState: Object = {loadingMore: false}; | ||
_appendAssets = (data: Object) => { |
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.
This shouldn't be bound.
@RSNara I updated type definitions and get rid of $FlowFixMe, I indeed had to export types from CameraRoll, what do you think ? |
…o cameraRollView
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.
Almost there, but I realized that we have a lot of $FlowFixMe
s in this file, which is really bad since they can suppress valid flow/js errors. I think, where possible, we should try to get rid of them, because they make flow less likely to catch errors.
RNTester/js/CameraRollView.js
Outdated
rendererChanged: function() { | ||
var ds = new ListView.DataSource({rowHasChanged: this._rowHasChanged}); | ||
rendererChanged() { | ||
const ds = new ListView.DataSource({rowHasChanged: rowHasChanged}); | ||
this.state.dataSource = ds.cloneWithRows( | ||
// $FlowFixMe(>=0.41.0) |
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.
I think the general rule of thumb should be: If you see a $FlowFixMe
, try to see if you can remove it.
Pretty sure this is suppressing some valid flow errors. For example, rowHasChanged
takes an array of Image
components, but this.state.assets
is of type Array<GetPhotosEdge>
.
RNTester/js/CameraRollView.js
Outdated
|
||
/* $FlowFixMe(>=0.68.0 site=react_native_fb) This comment suppresses an error | ||
* found when Flow v0.68 was deployed. To see the error delete this comment | ||
* and run Flow. */ | ||
UNSAFE_componentWillReceiveProps: function(nextProps: {groupTypes?: string}) { | ||
UNSAFE_componentWillReceiveProps(nextProps: {groupTypes?: string}) { |
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.
Can we remove this $FlowFixMe
?
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.
Not sure how we can remove it properly though.
This is the Flow error I get :
Cannot extend property Component [1] with CameraRollView because property groupTypes is read-only in object type [2] but writable in object type [3] in the first argument of property UNSAFE_componentWillReceiveProps.
Libraries/CameraRoll/CameraRoll.js
Outdated
heading?: number, | ||
speed?: number, | ||
}, | ||
export type GetPhotosEdge = { |
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.
What do you think about renaming this to:
export type PhotoIdentifierObject = {
Or:
export type PhotoIdentifier = {
Libraries/CameraRoll/CameraRoll.js
Outdated
}, | ||
}; | ||
|
||
export type GetPhotosReturn = { |
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.
What do you think about renaming this to:
export type PhotoIdentifierObjectsPage = {
Or:
export type PhotoIdentifiersPage = {
@RSNara I got rid of every $FlowFixMe, I don't really like the PropsObject type but I think it works |
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.
Thanks so much! This is so much better now. 😁
Edit: What do you mean by PropsObject
type?
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.
RSNara has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
The Props "sub" type representation, the actual prop types object (wrapped by $ReadOnly<>) |
Ah, that was no biggie. I fixed that on my end. 😁 |
Closing manually since this has been merged. |
Related to #21581
Remove createReactClass from CameraRollView.
Test Plan:
Release Notes:
[GENERAL] [ENHANCEMENT] [CameraRollView.js] - rm createReactClass