Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
fix: should require NativeComponent only on android
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 committed Apr 13, 2023
1 parent ac569c9 commit ee946ab
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/native.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Platform, requireNativeComponent, UIManager } from 'react-native';
import { Platform, requireNativeComponent, UIManager, View } from 'react-native';

import type { ScrollViewEnhancerProps } from './types';
import { warningOnHorizontalScroll } from './utils';
Expand All @@ -11,14 +11,19 @@ const LINKING_ERROR =
'- You are not using Expo Go\n';

const ComponentName = 'ScrollViewEnhancerView';
export const NativeView =
UIManager.getViewManagerConfig(ComponentName) != null
? requireNativeComponent<ScrollViewEnhancerProps>(ComponentName)
: () => {
throw new Error(LINKING_ERROR);
};
export const NativeView = (() => {
if (Platform.OS === 'android') {
return UIManager.getViewManagerConfig(ComponentName) != null
? requireNativeComponent<ScrollViewEnhancerProps>(ComponentName)
: () => {
throw new Error(LINKING_ERROR);
};
} else {
return View;
}
})();

export const ScrollViewEnhancerView = (props: ScrollViewEnhancerProps) => {
if (__DEV__) warningOnHorizontalScroll(props);
if (__DEV__ && Platform.OS === 'android') warningOnHorizontalScroll(props);
return <NativeView {...props} />;
};

0 comments on commit ee946ab

Please sign in to comment.