Skip to content

Commit

Permalink
Allow passing style to SafeAreaProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Jun 13, 2020
1 parent f494279 commit ba33b31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/SafeArea.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { NativeSyntheticEvent, ViewStyle, ViewProps } from 'react-native';
import {
NativeSyntheticEvent,
StyleProp,
ViewProps,
ViewStyle,
} from 'react-native';

export type Edge = 'top' | 'right' | 'bottom' | 'left';

Expand Down Expand Up @@ -27,7 +32,7 @@ export type InsetChangeNativeCallback = (event: InsetChangedEvent) => void;

export interface NativeSafeAreaProviderProps {
children?: React.ReactNode;
style?: ViewStyle;
style?: StyleProp<ViewStyle>;
onInsetsChange: InsetChangeNativeCallback;
}

Expand Down
9 changes: 7 additions & 2 deletions src/SafeAreaContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { StyleSheet, Dimensions } from 'react-native';
import { Dimensions, StyleProp, StyleSheet, ViewStyle } from 'react-native';
import NativeSafeAreaProvider from './NativeSafeAreaProvider';
import { EdgeInsets, InsetChangedEvent, Metrics, Rect } from './SafeArea.types';

Expand All @@ -16,12 +16,14 @@ export interface SafeAreaViewProps {
* @deprecated
*/
initialSafeAreaInsets?: EdgeInsets | null;
style?: StyleProp<ViewStyle>;
}

export function SafeAreaProvider({
children,
initialMetrics,
initialSafeAreaInsets,
style,
}: SafeAreaViewProps) {
const parentInsets = useParentSafeAreaInsets();
const parentFrame = useParentSafeAreaFrame();
Expand All @@ -47,7 +49,10 @@ export function SafeAreaProvider({
}, []);

return (
<NativeSafeAreaProvider style={styles.fill} onInsetsChange={onInsetsChange}>
<NativeSafeAreaProvider
style={[styles.fill, style]}
onInsetsChange={onInsetsChange}
>
{insets != null ? (
<SafeAreaFrameContext.Provider value={frame}>
<SafeAreaInsetsContext.Provider value={insets}>
Expand Down

0 comments on commit ba33b31

Please sign in to comment.