Skip to content

[createReactClass] Remove createReactClass from CameraRollView - #21619

Closed
exced wants to merge 6 commits into
react:masterfrom
exced:cameraRollView
Closed

[createReactClass] Remove createReactClass from CameraRollView#21619
exced wants to merge 6 commits into
react:masterfrom
exced:cameraRollView

Conversation

@exced

@exced exced commented Oct 10, 2018

Copy link
Copy Markdown
Contributor

Related to #21581

Remove createReactClass from CameraRollView.

Test Plan:

  • All flow tests succeed.
  • Run RNTester app, go to CameraViewExample component, scroll, update image size, groupTypes.

Release Notes:

[GENERAL] [ENHANCEMENT] [CameraRollView.js] - rm createReactClass

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 10, 2018

@RSNara RSNara left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread RNTester/js/CameraRollView.js Outdated
}

_fetch: async function(clear?: boolean) {
_fetch = async (clear?: boolean) => {

Copy link
Copy Markdown
Contributor

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) {

Comment thread 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,

Copy link
Copy Markdown
Contributor

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).

Comment thread RNTester/js/CameraRollView.js Outdated
rowID: string,
) {
var images = rowData.map(image => {
_renderRow = (rowData: Array<Image>, sectionID: string, rowID: string) => {

Copy link
Copy Markdown
Contributor

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.

Comment thread RNTester/js/CameraRollView.js Outdated
}

_rowHasChanged: function(r1: Array<Image>, r2: Array<Image>): boolean {
_rowHasChanged(r1: Array<Image>, r2: Array<Image>): boolean {

Copy link
Copy Markdown
Contributor

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. 😞

Copy link
Copy Markdown
Contributor

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.

Comment thread RNTester/js/CameraRollView.js Outdated
var newState: Object = {loadingMore: false};
_appendAssets = (data: Object) => {
const assets = data.edges;
const newState: Object = {loadingMore: false};

Copy link
Copy Markdown
Contributor

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 };

Comment thread RNTester/js/CameraRollView.js Outdated
import type {RNTesterProps} from 'RNTesterTypes';

type Props = $ReadOnly<{|
...RNTesterProps,

Copy link
Copy Markdown
Contributor

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?

Comment thread RNTester/js/CameraRollView.js Outdated
_appendAssets: function(data: Object) {
var assets = data.edges;
var newState: Object = {loadingMore: false};
_appendAssets = (data: Object) => {

Copy link
Copy Markdown
Contributor

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.

@exced

exced commented Oct 10, 2018

Copy link
Copy Markdown
Contributor Author

@RSNara I updated type definitions and get rid of $FlowFixMe, I indeed had to export types from CameraRoll, what do you think ?

@RSNara RSNara left a comment

Copy link
Copy Markdown
Contributor

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 $FlowFixMes 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.

Comment thread RNTester/js/CameraRollView.js Outdated
rendererChanged() {
const ds = new ListView.DataSource({rowHasChanged: rowHasChanged});
this.state.dataSource = ds.cloneWithRows(
// $FlowFixMe(>=0.41.0)

Copy link
Copy Markdown
Contributor

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>.

Comment thread RNTester/js/CameraRollView.js Outdated
* 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}) {

Copy link
Copy Markdown
Contributor

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?

@exced exced Oct 11, 2018

Copy link
Copy Markdown
Contributor Author

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.

Comment thread RNTester/js/CameraRollView.js
Comment thread RNTester/js/CameraRollView.js
Comment thread RNTester/js/CameraRollView.js
Comment thread Libraries/CameraRoll/CameraRoll.js Outdated
heading?: number,
speed?: number,
},
export type GetPhotosEdge = {

Copy link
Copy Markdown
Contributor

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 = {

Comment thread Libraries/CameraRoll/CameraRoll.js Outdated
},
};

export type GetPhotosReturn = {

Copy link
Copy Markdown
Contributor

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 = {

@exced

exced commented Oct 11, 2018

Copy link
Copy Markdown
Contributor Author

@RSNara I got rid of every $FlowFixMe, I don't really like the PropsObject type but I think it works

@RSNara RSNara left a comment

Copy link
Copy Markdown
Contributor

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?

@RSNara RSNara changed the title Remove createReactClass from CameraRollView [createReactClass] Remove createReactClass from CameraRollView Oct 11, 2018

@facebook-github-bot facebook-github-bot left a comment

Copy link
Copy Markdown
Contributor

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.

@exced

exced commented Oct 12, 2018

Copy link
Copy Markdown
Contributor Author

The Props "sub" type representation, the actual prop types object (wrapped by $ReadOnly<>)

@RSNara

RSNara commented Oct 12, 2018

Copy link
Copy Markdown
Contributor

Ah, that was no biggie. I fixed that on my end. 😁

@RSNara

RSNara commented Oct 22, 2018

Copy link
Copy Markdown
Contributor

Closing manually since this has been merged.

@RSNara RSNara closed this Oct 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants