Skip to content

Commit eb83858

Browse files
committed
fix: fix bottom positions when useRNScreensOverlay is true
1 parent 48a08f6 commit eb83858

6 files changed

Lines changed: 64 additions & 62 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,11 @@
3535
- **Alert component:** Renamed `alertType` prop to `type` for consistency with other components. The `alertType` prop remains available but will be deprecated, so please migrate to `type`.
3636
- **Notification component:** Changed default `borderRadius` from `5` to `8` and "description" `fontSize` from `14` to `15`.
3737
- **Notification component:** Introduced a `type` prop. When set to anything other than `'classic'`, an icon and left border will be displayed.
38+
- `useRNScreensOverlay` and `rnScreensOverlayViewStyle` accepted not only as props, but also as parameters of the `showNotification` method.
3839

3940
### Bug Fixes
4041
- When you mount `NotifierWrapper`/`NotifierRoot` with `omitGlobalMethodsHookup={true}` and then switch it to `false`, global methods now hook up correctly.
4142
- Fixed a jump in the appearing animation when very large notifications appear.
4243

4344
### Known Issues
44-
- When `useRNScreensOverlay` is `true`, the bottom `position` will not work. If you need a bottom position with `useRNScreensOverlay`, you can adjust the container style using the `rnScreensOverlayViewStyle` parameter, for example:
45-
46-
```typescript
47-
rnScreensOverlayViewStyle={{
48-
width: '100%',
49-
position: 'absolute',
50-
bottom: 0,
51-
}}
52-
```
5345
- When `useRNScreensOverlay` is `true`, `SafeAreaView` might not work correctly. Use `ViewWithOffsets` component that is coming though props into all **Custom Components**.

src/components/FullWindowOverlay.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { ReactNode } from 'react';
22
import { Platform, View, type StyleProp, type ViewStyle } from 'react-native';
3+
import type { Position } from '../types';
4+
import { styles } from '../styles';
35

46
let RNScreenFullWindowOverlay:
57
| ((props: { children: React.ReactNode }) => React.JSX.Element)
@@ -10,19 +12,29 @@ try {
1012

1113
interface FullWindowOverlayProps {
1214
children: ReactNode;
15+
position: Position;
1316
useOverlay?: boolean;
1417
viewStyle?: StyleProp<ViewStyle>;
1518
}
1619
export const FullWindowOverlay = ({
1720
children,
21+
position,
1822
useOverlay,
1923
viewStyle,
2024
}: FullWindowOverlayProps) => {
2125
if (Platform.OS !== 'ios' || !useOverlay || !RNScreenFullWindowOverlay)
2226
return children;
27+
28+
const isBottom =
29+
position === 'bottom' ||
30+
position === 'bottomLeft' ||
31+
position === 'bottomRight';
32+
2333
return (
2434
<RNScreenFullWindowOverlay>
25-
<View style={viewStyle}>{children}</View>
35+
<View style={[isBottom && styles.bottomFullWindowOverlay, viewStyle]}>
36+
{children}
37+
</View>
2638
</RNScreenFullWindowOverlay>
2739
);
2840
};

src/components/Notifier.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
NotifierProps,
1212
ShowNotificationParams,
1313
} from '../types';
14-
import { FullWindowOverlay } from './FullWindowOverlay';
1514
import { NotifierManager } from './NotifierManager';
1615

1716
// we store references to all currently mounted instances of NotifierRoot / NotifierWrapper where omitGlobalMethodsHookup != true
@@ -32,19 +31,13 @@ const removeRef = (ref: NotifierInterface | null) => {
3231

3332
/** Responsibilities:
3433
* - manages refs to display last mounted notification, or broadcast to all
35-
* - render FullWindowOverlay when useRNScreensOverlay is true
3634
* - collects default params from props and stores them in the ref to avoid re-renders of the NotifierManager.
3735
*/
3836
const NotifierRootComponent = React.forwardRef<
3937
NotifierInterface,
4038
NotifierProps
4139
>((props, ref) => {
42-
const {
43-
omitGlobalMethodsHookup,
44-
useRNScreensOverlay,
45-
rnScreensOverlayViewStyle,
46-
...defaultParamsProps
47-
} = props;
40+
const { omitGlobalMethodsHookup, ...defaultParamsProps } = props;
4841
const localRef = useRef<NotifierInterface | null>(null);
4942

5043
// since we don't rely on defaultParamsProps during the render, and access it only during "showNotification" call
@@ -80,14 +73,7 @@ const NotifierRootComponent = React.forwardRef<
8073
[ref, omitGlobalMethodsHookup]
8174
);
8275

83-
return (
84-
<FullWindowOverlay
85-
useOverlay={useRNScreensOverlay}
86-
viewStyle={rnScreensOverlayViewStyle}
87-
>
88-
<NotifierManager ref={setRef} defaultParams={defaultParams} />
89-
</FullWindowOverlay>
90-
);
76+
return <NotifierManager ref={setRef} defaultParams={defaultParams} />;
9177
});
9278

9379
const getLastRef = () => {

src/components/NotifierRenderer.tsx

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { RenderComponentWithOffsets } from './RenderComponentWithOffsets';
2020
import { useShaking } from '../hooks/useShaking';
2121
import { useLayout } from '../hooks/useLayout';
2222
import { useSwipeAnimationValues } from '../hooks/useSwipeAnimationValues';
23+
import { FullWindowOverlay } from './FullWindowOverlay';
2324

2425
export interface NotifierRendererMethods {
2526
hideNotification(callback?: Animated.EndCallback): void;
@@ -209,32 +210,38 @@ const NotifierRendererComponent = forwardRef<
209210
);
210211

211212
return (
212-
<PanGestureHandler
213-
enabled={notification.swipeDirection !== 'none'}
214-
onGestureEvent={onGestureEvent}
215-
onHandlerStateChange={onHandlerStateChange}
213+
<FullWindowOverlay
214+
position={notification.position}
215+
useOverlay={notification.useRNScreensOverlay}
216+
viewStyle={notification.rnScreensOverlayViewStyle}
216217
>
217-
<Animated.View
218-
{...notification.containerProps}
219-
ref={ref}
220-
style={[
221-
styles.container,
222-
positionStyles[notification.position],
223-
notification.containerStyle,
224-
animationStyle,
225-
]}
218+
<PanGestureHandler
219+
enabled={notification.swipeDirection !== 'none'}
220+
onGestureEvent={onGestureEvent}
221+
onHandlerStateChange={onHandlerStateChange}
226222
>
227-
<TouchableWithoutFeedback onPress={onPress}>
228-
<View ref={ref} onLayout={onLayout}>
229-
<RenderComponentWithOffsets
230-
notification={notification}
231-
hide={hideNotification}
232-
animationFunctionParams={animationFunctionParams}
233-
/>
234-
</View>
235-
</TouchableWithoutFeedback>
236-
</Animated.View>
237-
</PanGestureHandler>
223+
<Animated.View
224+
{...notification.containerProps}
225+
ref={ref}
226+
style={[
227+
styles.container,
228+
positionStyles[notification.position],
229+
notification.containerStyle,
230+
animationStyle,
231+
]}
232+
>
233+
<TouchableWithoutFeedback onPress={onPress}>
234+
<View ref={ref} onLayout={onLayout}>
235+
<RenderComponentWithOffsets
236+
notification={notification}
237+
hide={hideNotification}
238+
animationFunctionParams={animationFunctionParams}
239+
/>
240+
</View>
241+
</TouchableWithoutFeedback>
242+
</Animated.View>
243+
</PanGestureHandler>
244+
</FullWindowOverlay>
238245
);
239246
});
240247

src/styles.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ export const styles = StyleSheet.create({
55
zIndex: 2,
66
position: 'absolute',
77
},
8+
bottomFullWindowOverlay: {
9+
position: 'absolute',
10+
bottom: 0,
11+
width: '100%',
12+
},
813
});
914

1015
export const positionStyles = StyleSheet.create({

src/types.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,18 @@ export interface ShowNotificationParams<
349349
* }
350350
* */
351351
shakingConfig?: ShakingConfig;
352+
353+
/** use FullWindowOverlay component from react-native-screens library
354+
* If true, Notifier will be rendered above NativeStackNavigation modals and RN Modal on iOS.
355+
* This Option will work only if react-native-screens library is installed.
356+
* @platform iOS
357+
* @default false */
358+
useRNScreensOverlay?: boolean;
359+
360+
/** Style that will be used for RN View that is inside of FullWindowOverlay
361+
* @platform iOS
362+
* @default null */
363+
rnScreensOverlayViewStyle?: StyleProp<ViewStyle>;
352364
}
353365

354366
export enum AnimationState {
@@ -389,18 +401,6 @@ export interface NotifierProps extends ShowNotificationParams {
389401
* If enabled, the only way to display notifications is using refs.
390402
* @default false */
391403
omitGlobalMethodsHookup?: boolean;
392-
/** use FullWindowOverlay component from react-native-screens library
393-
* If true, Notifier will be rendered above NativeStackNavigation modals and RN Modal on iOS.
394-
* This Option will work only if react-native-screens library is installed.
395-
* It's recommended to not change this value on the fly as FullWindowOverlay might not work correctly
396-
* @platform iOS
397-
* @default false */
398-
useRNScreensOverlay?: boolean;
399-
400-
/** Style that will be used for RN View that is inside of FullWindowOverlay
401-
* @platform iOS
402-
* @default null */
403-
rnScreensOverlayViewStyle?: StyleProp<ViewStyle>;
404404
}
405405

406406
export type UpdateNotificationParams<

0 commit comments

Comments
 (0)