APSL / react-native-keyboard-aware-scroll-view

A ScrollView component that handles keyboard appearance and automatically scrolls to focused TextInput.
MIT License
5.27k stars 646 forks source link

Newest version has a missing check, breaks jest tests #485

Open kevryan2 opened 3 years ago

kevryan2 commented 3 years ago

Version 0.9.4 released today breaks at line 135 https://prnt.sc/129rhwg.

Addition that caused the issue: https://prnt.sc/129rjt2.

Recommendation: const shouldCallGetNode = !Platform.constants || !Platform.constants.reactNativeVersion || (Platform.constants.reactNativeVersion.major === 0 && Platform.constants.reactNativeVersion.minor < 62)

maxckelly commented 3 years ago

Have you managed to find a work around for this @KevRyan2 ?

TNicholson11 commented 3 years ago

I'm running into this same issue upgrading a project to React Native 0.64.0... I ended up mocking the reactNativeVersion object in our testing utility that utilizes react-test-renderer calls in our project. Definitely hoping there's a fix on the way soon.

import { Platform } from 'react-native';
...
Platform.constants.reactNativeVersion = { minor: '64', major: '0' };
...
kevryan2 commented 3 years ago

Have you managed to find a work around for this @KevRyan2 ?

Yes just hardcode it to an older version in your package.json dependencies. It won't benefit from any upgrades or optimizations until you change that back, but it won't break at least.

robrechtme commented 3 years ago

This is my workaround:

jest.mock('react-native/Libraries/Utilities/Platform', () => {
  const Platform = jest.requireActual('react-native/Libraries/Utilities/Platform');
  Platform.constants.reactNativeVersion = { major: 0, minor: 64, patch: 0 };
  return Platform;
});