Skip to content
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

Fix ScrollView getInnerViewNode and getInnerViewRef ref methods #30588

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Libraries/Components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,13 +808,13 @@ class ScrollView extends React.Component<Props, State> {
return ReactNative.findNodeHandle(this._scrollViewRef);
};

getInnerViewNode(): ?number {
getInnerViewNode: () => ?number = () => {
return ReactNative.findNodeHandle(this._innerViewRef);
}
};

getInnerViewRef(): ?React.ElementRef<typeof View> {
getInnerViewRef: () => ?React.ElementRef<typeof View> = () => {
return this._innerViewRef;
}
};

getNativeScrollRef: () => ?React.ElementRef<HostComponent<mixed>> = () => {
return this._scrollViewRef;
Expand Down
16 changes: 16 additions & 0 deletions Libraries/Components/ScrollView/__tests__/ScrollView-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,20 @@ describe('<ScrollView />', () => {
jest.fn().constructor,
);
});
it('getInnerViewRef for case where it returns a native view', () => {
jest.resetModules();
jest.unmock('../ScrollView');

const scrollViewRef = React.createRef(null);

ReactTestRenderer.create(<ScrollView ref={scrollViewRef} />);

const innerViewRef = scrollViewRef.current.getInnerViewRef();

// This is checking if the ref acts like a host component. If we had an
// `isHostComponent(ref)` method, that would be preferred.
expect(innerViewRef.measure).toBeInstanceOf(jest.fn().constructor);
expect(innerViewRef.measureLayout).toBeInstanceOf(jest.fn().constructor);
expect(innerViewRef.measureInWindow).toBeInstanceOf(jest.fn().constructor);
});
});