Skip to content

Commit 6e36d04

Browse files
vshabfacebook-github-bot
authored andcommitted
Fix ScrollView getInnerViewNode and getInnerViewRef ref methods (#30588)
Summary: Currently ScrollView ref's `getInnerViewNode` and `getInnerViewRef` are unbound and don't work as expected returning empty values. The origin of this problem probably is issued by d2f314a Working example of the problem is available here: https://github.com/vshab/RNGetInnerViewBug This PR binds getInnerViewNode and getInnerViewRef to ScrollView and adds test checking the value of getInnerViewRef. Before: ![Simulator Screen Shot - iPhone 11 - 2020-12-15 at 02 07 03](https://user-images.githubusercontent.com/6755908/102149544-c7df4900-3e7f-11eb-89de-de39a28fbdb3.png) After: ![Simulator Screen Shot - iPhone 11 - 2020-12-15 at 01 49 31](https://user-images.githubusercontent.com/6755908/102149559-d168b100-3e7f-11eb-8b27-031c9e43112c.png) ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [JavaScript] [Fixed] - ScrollView: Fix `getInnerViewNode` and `getInnerViewRef` ref methods Pull Request resolved: #30588 Test Plan: 1. The test checking the value of getInnerViewRef is added. 2. Example app demonstrating the problem is provided with before/after screenshots. Reviewed By: TheSavior, nadiia Differential Revision: D25916413 Pulled By: kacieb fbshipit-source-id: bf18079682be7c647b8715bd0f36cf84953abcfa
1 parent cfd39bc commit 6e36d04

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Libraries/Components/ScrollView/ScrollView.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -808,13 +808,13 @@ class ScrollView extends React.Component<Props, State> {
808808
return ReactNative.findNodeHandle(this._scrollViewRef);
809809
};
810810

811-
getInnerViewNode(): ?number {
811+
getInnerViewNode: () => ?number = () => {
812812
return ReactNative.findNodeHandle(this._innerViewRef);
813-
}
813+
};
814814

815-
getInnerViewRef(): ?React.ElementRef<typeof View> {
815+
getInnerViewRef: () => ?React.ElementRef<typeof View> = () => {
816816
return this._innerViewRef;
817-
}
817+
};
818818

819819
getNativeScrollRef: () => ?React.ElementRef<HostComponent<mixed>> = () => {
820820
return this._scrollViewRef;

Libraries/Components/ScrollView/__tests__/ScrollView-test.js

+16
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,20 @@ describe('<ScrollView />', () => {
4848
jest.fn().constructor,
4949
);
5050
});
51+
it('getInnerViewRef for case where it returns a native view', () => {
52+
jest.resetModules();
53+
jest.unmock('../ScrollView');
54+
55+
const scrollViewRef = React.createRef(null);
56+
57+
ReactTestRenderer.create(<ScrollView ref={scrollViewRef} />);
58+
59+
const innerViewRef = scrollViewRef.current.getInnerViewRef();
60+
61+
// This is checking if the ref acts like a host component. If we had an
62+
// `isHostComponent(ref)` method, that would be preferred.
63+
expect(innerViewRef.measure).toBeInstanceOf(jest.fn().constructor);
64+
expect(innerViewRef.measureLayout).toBeInstanceOf(jest.fn().constructor);
65+
expect(innerViewRef.measureInWindow).toBeInstanceOf(jest.fn().constructor);
66+
});
5167
});

0 commit comments

Comments
 (0)