Skip to content

Commit 88f497f

Browse files
committed
Add Top Start Position of Overlay with Safe Area Insets
1 parent f1c2020 commit 88f497f

5 files changed

Lines changed: 39 additions & 22 deletions

File tree

packages/carbon-react-native/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@audira/carbon-react-native",
3-
"version": "1.0.0-beta.10",
3+
"version": "1.0.0-beta.11",
44
"license": "MIT",
55
"homepage": "https://rakadoank.github.io/carbon-react-native",
66
"repository": "https://github.com/RakaDoank/carbon-react-native",

packages/carbon-react-native/src/providers/toast/_overlay/Overlay.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ import {
1313
type LayoutChangeEvent,
1414
} from "react-native"
1515

16-
import {
17-
Spacing,
18-
} from "@audira/carbon-react-native-elements"
19-
2016
import {
2117
GlobalConfigContext,
2218
} from "../../../_internal/contexts"
@@ -34,6 +30,10 @@ import {
3430
type ComponentWrapperRef,
3531
} from "./_component-wrapper"
3632

33+
import {
34+
Gap,
35+
} from "./_gap"
36+
3737
export const Overlay = forwardRef<OverlayRef>(
3838
function(
3939
___props,
@@ -91,12 +91,12 @@ export const Overlay = forwardRef<OverlayRef>(
9191
) {
9292
componentWrappersRef.current[index].cancelX() // cancel the current delay first
9393
componentWrappersRef.current[index].shiftX(
94-
componentsConfig.current[index].width + Spacing.spacing_03,
94+
componentsConfig.current[index].width + Gap,
9595
)
9696
if(index > 0) {
9797
for(let i = 0; i < index; i++) {
9898
componentWrappersRef.current[i]?.shiftY(
99-
-componentsConfig.current[index].height - Spacing.spacing_03,
99+
-componentsConfig.current[index].height - Gap,
100100
)
101101
}
102102
}
@@ -127,14 +127,14 @@ export const Overlay = forwardRef<OverlayRef>(
127127
}
128128

129129
componentWrappersRef.current[index].shiftX(
130-
-componentsConfig.current[index].width - Spacing.spacing_03,
130+
-componentsConfig.current[index].width - Gap,
131131
)
132132

133133
if(componentWrappersRef.current.length > 1) {
134134
for(let i = 0; i < componentWrappersRef.current.length - 1; i++) {
135135
componentWrappersRef.current[i]?.shiftY(
136136
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion, @typescript-eslint/no-extra-non-null-assertion
137-
componentsConfig.current[0]!!.height + Spacing.spacing_03,
137+
componentsConfig.current[0]!!.height + Gap,
138138
)
139139
}
140140
}
@@ -151,12 +151,12 @@ export const Overlay = forwardRef<OverlayRef>(
151151

152152
if(componentsConfig.current[index]?.state === 1) {
153153
componentWrappersRef.current[index]?.shiftX(
154-
componentsConfig.current[index].width + Spacing.spacing_03,
154+
componentsConfig.current[index].width + Gap,
155155
componentsConfig.current[index].duration ?? globalConfigContext.toastDuration,
156156
)
157157
} else if(
158158
componentsConfig.current[index]?.state === 2 &&
159-
!componentsConfig.current.some(config => config.state < 2) // somehow, the state may increase to "3" when it's dismissed by click/press. only god knows it.
159+
!componentsConfig.current.some(config => config.state < 2)
160160
) {
161161
// Delete all componentsConfig, componentWrappersRef, and components (react state) when it's all done
162162
componentsConfig.current.splice(0, componentsConfig.current.length)

packages/carbon-react-native/src/providers/toast/_overlay/_component-wrapper/ComponentWrapper.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@ import {
1414

1515
import {
1616
Motion,
17-
Spacing,
1817
} from "@audira/carbon-react-native-elements"
1918

19+
import {
20+
useSafeAreaInsets,
21+
} from "react-native-safe-area-context"
22+
23+
import {
24+
Gap,
25+
} from "../_gap"
26+
2027
import type {
2128
ComponentWrapperProps,
2229
} from "./ComponentWrapperProps"
@@ -37,14 +44,17 @@ export const ComponentWrapper = forwardRef<ComponentWrapperRef, ComponentWrapper
3744
) {
3845

3946
const
47+
safeAreaInsets =
48+
useSafeAreaInsets(),
49+
4050
translateX =
4151
useRef(new Animated.Value(0)),
4252

4353
translateXValueJS =
4454
useRef(0),
4555

4656
translateY =
47-
useRef(new Animated.Value(0)),
57+
useRef(new Animated.Value(safeAreaInsets.top + Gap)),
4858

4959
translateYValueJS =
5060
useRef(0)
@@ -148,13 +158,15 @@ const
148158
StyleSheet.create({
149159
componentWrapper: {
150160
position: "absolute",
151-
top: Spacing.spacing_03,
152161
left: "100%",
153162
width: "auto",
154163
...Platform.select({
155164
web: {
156165
flexDirection: "row",
157166
},
167+
android: {
168+
top: Gap, // iOS doesn't need this, Apple handles it internally
169+
},
158170
}),
159171
},
160172
}),
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {
2+
Spacing,
3+
} from "@audira/carbon-react-native-elements"
4+
5+
export const Gap = Spacing.spacing_03

storybook/.storybook-rn/preview.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from "react-native"
1111

1212
import type {
13-
Decorator,
13+
// Decorator,
1414
Preview,
1515
} from "@storybook/react-native"
1616

@@ -29,9 +29,9 @@ const preview: Preview = {
2929
Story => (
3030
<SafeAreaProvider>
3131
<CarbonReactNative>
32-
<Body
33-
Story={ Story }
34-
/>
32+
<Body>
33+
<Story/>
34+
</Body>
3535
</CarbonReactNative>
3636
</SafeAreaProvider>
3737
),
@@ -46,10 +46,11 @@ const preview: Preview = {
4646

4747
export default preview
4848
interface BodyProps {
49-
Story: Parameters<Decorator>[0],
49+
// Story: Parameters<Decorator>[0],
50+
children?: React.ReactNode,
5051
}
5152
function Body({
52-
Story,
53+
children,
5354
}: BodyProps) {
5455

5556
const
@@ -71,7 +72,7 @@ function Body({
7172
style={ [styleSheet.root, carbonStyleSheet.root] }
7273
contentContainerStyle={ styleSheet.scrollContentContainer }
7374
>
74-
<Story/>
75+
{ children }
7576
</ScrollView>
7677
)
7778

@@ -84,7 +85,6 @@ const
8485
flex: 1,
8586
},
8687
scrollContentContainer: {
87-
padding: 16,
8888
flexGrow: 1,
8989
flexShrink: 1,
9090
flexBasis: "auto",

0 commit comments

Comments
 (0)