Skip to content

Commit

Permalink
refactor: allow passing style to the container
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed May 21, 2022
1 parent ce5115a commit 5e1ed9d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(

// styles
style: _providedStyle,
containerStyle: _providedContainerStyle,
backgroundStyle: _providedBackgroundStyle,
handleStyle: _providedHandleStyle,
handleIndicatorStyle: _providedHandleIndicatorStyle,
Expand Down Expand Up @@ -1604,6 +1605,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
topInset={topInset}
bottomInset={bottomInset}
detached={detached}
style={_providedContainerStyle}
>
<Animated.View style={containerStyle}>
<BottomSheetBackgroundContainer
Expand Down
12 changes: 9 additions & 3 deletions src/components/bottomSheet/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ export interface BottomSheetProps

//#endregion

//#region styles
/**
* View style to be applied to the container.
* @type ViewStyle
* @default undefined
*/
containerStyle?: StyleProp<ViewStyle>;
/**
* View style to be applied to the sheet container component,
* it also could be an Animated Style.
Expand All @@ -185,7 +192,6 @@ export interface BottomSheetProps
>;
/**
* View style to be applied to the background component.
*
* @type ViewStyle
* @default undefined
*/
Expand All @@ -194,18 +200,18 @@ export interface BottomSheetProps
>;
/**
* View style to be applied to the handle component.
*
* @type ViewStyle
* @default undefined
*/
handleStyle?: StyleProp<ViewStyle>;
/**
* View style to be applied to the handle indicator component.
*
* @type ViewStyle
* @default undefined
*/
handleIndicatorStyle?: StyleProp<ViewStyle>;
//#endregion

/**
* Custom hook to provide pan gesture events handler, which will allow advance and
* customize handling for pan gesture.
Expand Down
14 changes: 11 additions & 3 deletions src/components/bottomSheetContainer/BottomSheetContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React, { memo, useCallback, useMemo, useRef } from 'react';
import { LayoutChangeEvent, StatusBar, View, ViewStyle } from 'react-native';
import {
LayoutChangeEvent,
StatusBar,
StyleProp,
View,
ViewStyle,
} from 'react-native';
import { WINDOW_HEIGHT } from '../../constants';
import { print } from '../../utilities';
import { styles } from './styles';
Expand All @@ -12,20 +18,22 @@ function BottomSheetContainerComponent({
bottomInset = 0,
shouldCalculateHeight = true,
detached,
style,
children,
}: BottomSheetContainerProps) {
const containerRef = useRef<View>(null);
//#region styles
const containerStyle = useMemo<ViewStyle[]>(
const containerStyle = useMemo<StyleProp<ViewStyle>>(
() => [
style,
styles.container,
{
top: topInset,
bottom: bottomInset,
overflow: detached ? 'visible' : 'hidden',
},
],
[detached, topInset, bottomInset]
[style, detached, topInset, bottomInset]
);
//#endregion

Expand Down
3 changes: 2 additions & 1 deletion src/components/bottomSheetContainer/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ReactNode } from 'react';
import type { Insets } from 'react-native';
import type { Insets, StyleProp, ViewStyle } from 'react-native';
import type Animated from 'react-native-reanimated';
import type { BottomSheetProps } from '../bottomSheet/types';

Expand All @@ -10,5 +10,6 @@ export interface BottomSheetContainerProps
containerHeight: Animated.SharedValue<number>;
containerOffset: Animated.SharedValue<Insets>;
shouldCalculateHeight?: boolean;
style?: StyleProp<ViewStyle>;
children: ReactNode;
}

0 comments on commit 5e1ed9d

Please sign in to comment.