mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-01 01:59:10 +00:00
[fix] Callback ref less on Views by making classList constant
Close #1766
This commit is contained in:
committed by
Nicolas Gallagher
parent
933bd138ce
commit
18d5d449a7
@@ -127,6 +127,19 @@ describe('components/View', () => {
|
|||||||
expect(ref).toBeCalled();
|
expect(ref).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('is not called for props changes', () => {
|
||||||
|
const ref = jest.fn();
|
||||||
|
let rerender;
|
||||||
|
act(() => {
|
||||||
|
({ rerender } = render(<View ref={ref} testID="123" />));
|
||||||
|
});
|
||||||
|
expect(ref).toHaveBeenCalledTimes(1);
|
||||||
|
act(() => {
|
||||||
|
rerender(<View ref={ref} testID="1234" />);
|
||||||
|
});
|
||||||
|
expect(ref).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
test('node has imperative methods', () => {
|
test('node has imperative methods', () => {
|
||||||
const ref = React.createRef();
|
const ref = React.createRef();
|
||||||
act(() => {
|
act(() => {
|
||||||
|
|||||||
+7
-6
@@ -103,12 +103,6 @@ const View = forwardRef<ViewProps, *>((props, forwardedRef) => {
|
|||||||
const hasTextAncestor = useContext(TextAncestorContext);
|
const hasTextAncestor = useContext(TextAncestorContext);
|
||||||
const hostRef = useRef(null);
|
const hostRef = useRef(null);
|
||||||
|
|
||||||
const classList = [classes.view];
|
|
||||||
const style = StyleSheet.compose(
|
|
||||||
hasTextAncestor && styles.inline,
|
|
||||||
props.style
|
|
||||||
);
|
|
||||||
|
|
||||||
useElementLayout(hostRef, onLayout);
|
useElementLayout(hostRef, onLayout);
|
||||||
useResponderEvents(hostRef, {
|
useResponderEvents(hostRef, {
|
||||||
onMoveShouldSetResponder,
|
onMoveShouldSetResponder,
|
||||||
@@ -129,6 +123,11 @@ const View = forwardRef<ViewProps, *>((props, forwardedRef) => {
|
|||||||
onStartShouldSetResponderCapture
|
onStartShouldSetResponderCapture
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const style = StyleSheet.compose(
|
||||||
|
hasTextAncestor && styles.inline,
|
||||||
|
props.style
|
||||||
|
);
|
||||||
|
|
||||||
const supportedProps = pickProps(props);
|
const supportedProps = pickProps(props);
|
||||||
supportedProps.classList = classList;
|
supportedProps.classList = classList;
|
||||||
supportedProps.style = style;
|
supportedProps.style = style;
|
||||||
@@ -161,6 +160,8 @@ const classes = css.create({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const classList = [classes.view];
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
inline: {
|
inline: {
|
||||||
display: 'inline-flex'
|
display: 'inline-flex'
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ describe('modules/useMergeRefs', () => {
|
|||||||
expect(nextRef).toHaveBeenCalled();
|
expect(nextRef).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('ref is not called for each rerender', () => {
|
test('ref is not called for each rerender', () => {
|
||||||
const ref = jest.fn();
|
const ref = jest.fn();
|
||||||
let rerender;
|
let rerender;
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ describe('modules/useMergeRefs', () => {
|
|||||||
expect(ref).toHaveBeenCalledTimes(1);
|
expect(ref).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('ref is not called for props changes', () => {
|
test('ref is not called for props changes', () => {
|
||||||
const ref = jest.fn();
|
const ref = jest.fn();
|
||||||
let rerender;
|
let rerender;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user