Skip to content

Commit

Permalink
feat!: remove native components from public API (#2412)
Browse files Browse the repository at this point in the history
## Description

This PR removes native components from our API. The motivation is that
those shouldn't be available directly, only through our interface.

## Checklist

- [x] Ensured that CI passes
  • Loading branch information
maciekstosio authored Oct 21, 2024
1 parent 5ff656e commit d2f7c21
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/components/Screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type NativeScreenProps = Omit<
sheetLargestUndimmedDetent: number;
};

export const NativeScreen: React.ComponentType<NativeScreenProps> =
const NativeScreen: React.ComponentType<NativeScreenProps> =
ScreenNativeComponent as React.ComponentType<NativeScreenProps>;
const AnimatedNativeScreen = Animated.createAnimatedComponent(NativeScreen);
const AnimatedNativeModalScreen = Animated.createAnimatedComponent(
Expand Down
13 changes: 3 additions & 10 deletions src/components/ScreenContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,18 @@ import { isNativePlatformSupported, screensEnabled } from '../core';
import ScreenContainerNativeComponent from '../fabric/ScreenContainerNativeComponent';
import ScreenNavigationContainerNativeComponent from '../fabric/ScreenNavigationContainerNativeComponent';

export const NativeScreenContainer: React.ComponentType<ScreenContainerProps> =
Platform.OS !== 'web' ? (ScreenContainerNativeComponent as any) : View;
export const NativeScreenNavigationContainer: React.ComponentType<ScreenContainerProps> =
Platform.OS !== 'web'
? (ScreenNavigationContainerNativeComponent as any)
: View;

function ScreenContainer(props: ScreenContainerProps) {
const { enabled = screensEnabled(), hasTwoStates, ...rest } = props;

if (enabled && isNativePlatformSupported) {
if (hasTwoStates) {
const ScreenNavigationContainer =
Platform.OS === 'ios'
? NativeScreenNavigationContainer
: NativeScreenContainer;
? ScreenNavigationContainerNativeComponent
: ScreenContainerNativeComponent;
return <ScreenNavigationContainer {...rest} />;
}
return <NativeScreenContainer {...rest} />;
return <ScreenContainerNativeComponent {...rest} />;
}
return <View {...rest} />;
}
Expand Down
5 changes: 2 additions & 3 deletions src/components/ScreenContainer.web.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { View } from 'react-native';

export const NativeScreenContainer = View;
export const NativeScreenNavigationContainer = View;
const ScreenContainer = View;

export default View;
export default ScreenContainer;
7 changes: 2 additions & 5 deletions src/components/ScreenContentWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import React from 'react';
import { Platform, View, ViewProps } from 'react-native';
import { ViewProps } from 'react-native';
import ScreenContentWrapperNativeComponent from '../fabric/ScreenContentWrapperNativeComponent';

export const NativeScreenContentWrapper: React.ComponentType<ViewProps> =
Platform.OS !== 'web' ? (ScreenContentWrapperNativeComponent as any) : View;

function ScreenContentWrapper(props: ViewProps) {
return <NativeScreenContentWrapper collapsable={false} {...props} />;
return <ScreenContentWrapperNativeComponent collapsable={false} {...props} />;
}

export default ScreenContentWrapper;
3 changes: 1 addition & 2 deletions src/components/ScreenContentWrapper.web.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { View } from 'react-native';

export const NativeScreenContentWrapper = View;

const ScreenContentWrapper = View;

export default ScreenContentWrapper;
10 changes: 2 additions & 8 deletions src/components/ScreenFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import React from 'react';
import { Platform, View, ViewProps } from 'react-native';
import { ViewProps } from 'react-native';
import ScreenFooterNativeComponent from '../fabric/ScreenFooterNativeComponent';

/**
* Unstable API
*/
export const NativeScreenFooter: React.ComponentType<ViewProps> =
Platform.OS !== 'web' ? (ScreenFooterNativeComponent as any) : View;

/**
* Unstable API
*/
function ScreenFooter(props: ViewProps) {
return <NativeScreenFooter {...props} />;
return <ScreenFooterNativeComponent {...props} />;
}

export default ScreenFooter;
3 changes: 1 addition & 2 deletions src/components/ScreenFooter.web.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { View } from 'react-native';

export const NativeScreenFooter = View;

const ScreenFooter = View;

export default ScreenFooter;
4 changes: 3 additions & 1 deletion src/components/ScreenStack.web.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { View } from 'react-native';

export default View;
const ScreenStack = View;

export default ScreenStack;
4 changes: 2 additions & 2 deletions src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import SearchBarNativeComponent, {
} from '../fabric/SearchBarNativeComponent';
import { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';

export const NativeSearchBar: React.ComponentType<
const NativeSearchBar: React.ComponentType<
SearchBarNativeProps & { ref?: React.RefObject<SearchBarCommands> }
> &
typeof NativeSearchBarCommands =
SearchBarNativeComponent as unknown as React.ComponentType<SearchBarNativeProps> &
SearchBarCommandsType;
export const NativeSearchBarCommands: SearchBarCommandsType =
const NativeSearchBarCommands: SearchBarCommandsType =
SearchBarNativeCommands as SearchBarCommandsType;

type NativeSearchBarRef = React.ElementRef<typeof NativeSearchBar>;
Expand Down
5 changes: 2 additions & 3 deletions src/components/SearchBar.web.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { View } from 'react-native';

export const NativeSearchBar = View;
export const NativeSearchBarCommands = View;
const SearchBar = View;

export default View;
export default SearchBar;
35 changes: 5 additions & 30 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,10 @@ export {
*/
export {
default as Screen,
NativeScreen,
InnerScreen,
ScreenContext,
} from './components/Screen';

export {
default as ScreenContainer,
NativeScreenContainer,
NativeScreenNavigationContainer,
} from './components/ScreenContainer';

export { default as ScreenStack } from './components/ScreenStack';

export {
ScreenStackHeaderConfig,
ScreenStackHeaderSubview,
Expand All @@ -38,28 +29,12 @@ export {
ScreenStackHeaderSearchBarView,
} from './components/ScreenStackHeaderConfig';

export {
default as SearchBar,
NativeSearchBar,
NativeSearchBarCommands,
} from './components/SearchBar';

export { default as SearchBar } from './components/SearchBar';
export { default as ScreenContainer } from './components/ScreenContainer';
export { default as ScreenStack } from './components/ScreenStack';
export { default as FullWindowOverlay } from './components/FullWindowOverlay';

export {
default as ScreenFooter,
NativeScreenFooter,
} from './components/ScreenFooter';

export {
default as ScreenContentWrapper,
NativeScreenContentWrapper,
} from './components/ScreenContentWrapper';

/**
* Modules
*/
export { default as NativeScreensModule } from './fabric/NativeScreensModule';
export { default as ScreenFooter } from './components/ScreenFooter';
export { default as ScreenContentWrapper } from './components/ScreenContentWrapper';

/**
* Contexts
Expand Down

0 comments on commit d2f7c21

Please sign in to comment.