-
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
Flow: View can be a string? #15955
Comments
@bvaughn - any chance you can elucidate why View can be a string? You added a type suppression relating to this here. Looks like it has to do with something in React Fiber? Can we not reliably depend on the ref returned from |
Unfortunately, that is correct. Native view components ("host components") are represented as strings with React 16. This is true for React DOM (eg "div", "span", etc.) and React Native (eg "RCTView", "RCTText", etc). Previously, React 15 created a wrapper object around host components (which is why the Flow typing "worked" before) but this was inefficient so we removed it for 16. Internally, it looks like people are setting the ref-type to a mix of |
Thanks for responding!! Any idea if there is a way to get to Ideally the local position issues will be fixed, and if not hopefully the absolute positions will be added to the |
I had a new thought in bed last night: if people within Facebook are typing the parameter passed in to the It seems like the If that's the case, I just need to type the parameter to the My main question is: can the parameter to the |
That's correct @Ashoat, the value of For native components, React Native renderer creates an instance of For the time being, you could copy the following Flow types from the react codebase: type MeasureOnSuccessCallback = (
x: number,
y: number,
width: number,
height: number,
pageX: number,
pageY: number,
) => void;
type MeasureInWindowOnSuccessCallback = (
x: number,
y: number,
width: number,
height: number,
) => void;
type MeasureLayoutOnSuccessCallback = (
left: number,
top: number,
width: number,
height: number,
) => void;
// This would be the "ref" type for host components
type NativeMethodsMixinType = {
blur(): void,
focus(): void,
measure(callback: MeasureOnSuccessCallback): void,
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void,
measureLayout(
relativeToNativeNode: number,
onSuccess: MeasureLayoutOnSuccessCallback,
onFail: () => void,
): void,
setNativeProps(nativeProps: Object): void,
}; cc @calebmer: Let's talk about a way to make this work better for open source React Native + Flow users? (Maybe a way exists already that I'm unfamiliar with?) 1 The value of |
Unfortunately I can't assign this issue to myself for some reason, but I'll create a PR shortly that will hopefully provide a meaningful default Flow type for host components. Will post back here once it's done. |
My current solution is just: import type {
NativeMethodsMixinType,
} from 'react-native/Libraries/Renderer/shims/ReactNativeTypes'; And then use |
Using |
FYI this issue should be fixed by 11b4084. Someone (who has permissions to do so) can probably close this issue. |
Is this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
react-native -v
:node -v
:npm -v
:flow version
:Then, specify:
Target Platform: N/A, Flow static typesystem
Development Operating System: macOS
Build tools: N/A, Flow static typesystem
Steps to Reproduce
Expected Behavior
View should be a
React.Component
.Actual Behavior
View
is the result of callingrequireNativeComponent()
requireNativeComponent
returnsReact$ComponentType<any> | string
View
can be astring
Reproducible Demo
The text was updated successfully, but these errors were encountered: