-
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] DrawerLayoutAndroid: Convert to ES6 class #21980
[createReactClass] DrawerLayoutAndroid: Convert to ES6 class #21980
Conversation
getInnerViewNode: function() { | ||
return this.refs[INNERVIEW_REF].getInnerViewNode(); | ||
}, | ||
getInnerViewNode() { |
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.
Curious about thoughts on this. Is it left over from an old RN version? Not sure if it is safe to remove.
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.
There are no internal callsites of this. The only other thing that defines getInnerViewNode is ScrollView
and innerViewRef is never ScrollView. Let's kill it.
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 refactor is incomplete.
Did you consider doing 👇 to implement the NativeMethodsMixin
methods?
class DrawerLayoutAndroid extends React.Component<Props, State> {
// ...
blur(): void {
return this.nativeRef.blur();
}
focus(): void {
return this.nativeRef.focus();
}
measure(callback: MeasureOnSuccessCallback): void {
return this.nativeRef.measure(callback);
}
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void {
return this.nativeRef.measureInWindow(callback);
}
measureLayout(
relativeToNativeNode: number,
onSuccess: MeasureLayoutOnSuccessCallback,
onFail: () => void,
): void {
return this.nativeRef.measureLayout(
relativeToNativeNode,
onSuccess,
onFail,
);
}
setNativeProps(nativeProps: Object): void {
return this.nativeRef.setNativeProps(nativeProps);
}
// ...
}
My thoughts on why I did it that way: That would make the wrapper more complex, and would have to be changed whenever This is the approach Can, of course, update this if this is not a good option however! 👍 |
It seems like this is a problem with needing to add additional methods to the public API of the component when using As an additional data point, of the 8 or so callsites of this component inside of Facebook, they only use If we want to keep the API the same, I think I would bias towards what @RSNara proposed so that we can hide the implementation details. Otherwise maybe we should just drop support for the native methods? |
8fe2ac6
to
2d97b41
Compare
Implemented the native methods. Could also serve as some boilerplate for if this needs to be done on other classes in the future, too. How do you feel about this implementation? react-native/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js Lines 321 to 354 in 2d97b41
Also looks like CI is failing because circleci is not yet able to see the latest metro version on npm |
Thanks for iterating on this, @empyrical! |
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.
@empyrical merged commit bea3bb6 into |
Summary: This pull requests converts `DrawerLayoutAndroid` from a `createReactClass`-based component to an ES6 class component, removing its use of `NativeMethodsMixin` and `prop-types` in the process. Unfortunately this couldn't be moved over to a full `forwardRef` to the native component, because it has the methods `openDrawer` and `closeDrawer` as part of its API, and they can't be called directly on the native component. A `createRef`-based ref to the native component can be accessed from the `nativeRef` property of a `DrawerLayoutAndroid` instance if a native ref is needed. The Flow types for callbacks have also been filled out. Pull Request resolved: facebook#21980 Reviewed By: TheSavior Differential Revision: D12901951 Pulled By: RSNara fbshipit-source-id: d35fa5f11b1059f49b466b52abeec902db1d22f7
This pull requests converts
DrawerLayoutAndroid
from acreateReactClass
-based component to an ES6 class component, removing its use ofNativeMethodsMixin
andprop-types
in the process.Unfortunately this couldn't be moved over to a full
forwardRef
to the native component, because it has the methodsopenDrawer
andcloseDrawer
as part of its API, and they can't be called directly on the native component. AcreateRef
-based ref to the native component can be accessed from thenativeRef
property of aDrawerLayoutAndroid
instance if a native ref is needed.The Flow types for callbacks have also been filled out.
Test Plan:
yarn flow-check-android
passes. I've tried it out in the Android simulator, and no regressions have been noted.Release Notes:
[GENERAL] [ENHANCEMENT] [Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js] - Converted to class component