mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
6e36d046a3
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 https://github.com/facebook/react-native/commit/d2f314af75b63443db23e131aaf93c2d064e4f44 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:  After:  ## 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: https://github.com/facebook/react-native/pull/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
68 lines
2.0 KiB
JavaScript
68 lines
2.0 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @emails oncall+react_native
|
|
* @flow-strict
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const React = require('react');
|
|
const ScrollView = require('../ScrollView');
|
|
const ReactNativeTestTools = require('../../../Utilities/ReactNativeTestTools');
|
|
const ReactTestRenderer = require('react-test-renderer');
|
|
const View = require('../../View/View');
|
|
const Text = require('../../../Text/Text');
|
|
|
|
describe('<ScrollView />', () => {
|
|
it('should render as expected', () => {
|
|
ReactNativeTestTools.expectRendersMatchingSnapshot(
|
|
'ScrollView',
|
|
() => (
|
|
<ScrollView>
|
|
<View>
|
|
<Text>Hello World!</Text>
|
|
</View>
|
|
</ScrollView>
|
|
),
|
|
() => {
|
|
jest.dontMock('../ScrollView');
|
|
},
|
|
);
|
|
});
|
|
it('should mock native methods and instance methods when mocked', () => {
|
|
jest.resetModules();
|
|
jest.mock('../ScrollView');
|
|
const ref = React.createRef();
|
|
|
|
ReactTestRenderer.create(<ScrollView ref={ref} />);
|
|
|
|
expect(ref.current != null && ref.current.measure).toBeInstanceOf(
|
|
jest.fn().constructor,
|
|
);
|
|
expect(ref.current != null && ref.current.scrollTo).toBeInstanceOf(
|
|
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);
|
|
});
|
|
});
|