Skip to content

Commit

Permalink
Merge branch 'main' into fix-native-stack-titles-styles
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Mar 10, 2024
2 parents 3b895c4 + 3799b16 commit 5104ced
Show file tree
Hide file tree
Showing 21 changed files with 201 additions and 121 deletions.
12 changes: 9 additions & 3 deletions example/src/Screens/BottomTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
type NavigatorScreenParams,
type PathConfigMap,
useIsFocused,
useLocale,
} from '@react-navigation/native';
import { BlurView } from 'expo-blur';
import * as React from 'react';
Expand Down Expand Up @@ -83,6 +84,7 @@ const animations = ['none', 'fade', 'shift'] as const;

export function BottomTabs() {
const { showActionSheetWithOptions } = useActionSheet();
const { direction } = useLocale();

const dimensions = useWindowDimensions();

Expand Down Expand Up @@ -129,7 +131,11 @@ export function BottomTabs() {
/>
</HeaderButton>
),
tabBarPosition: isLargeScreen ? 'left' : 'bottom',
tabBarPosition: isLargeScreen
? direction === 'ltr'
? 'left'
: 'right'
: 'bottom',
tabBarLabelPosition:
isLargeScreen && isCompact ? 'below-icon' : undefined,
animation,
Expand Down Expand Up @@ -201,7 +207,7 @@ export function BottomTabs() {
intensity={100}
style={{
...StyleSheet.absoluteFillObject,
right: isLargeScreen
end: isLargeScreen
? // Offset for right border of the sidebar
-StyleSheet.hairlineWidth
: 0,
Expand All @@ -218,7 +224,7 @@ export function BottomTabs() {
style={{
position: 'absolute',
bottom: 0,
left: 0,
start: 0,
padding: 16,
}}
>
Expand Down
4 changes: 2 additions & 2 deletions example/src/Screens/DrawerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ const styles = StyleSheet.create({
realDrawer: {
position: 'absolute',
top: 0,
left: 0,
right: 8,
start: 0,
end: 8,
bottom: 0,
backgroundColor: '#ebdec1',
borderColor: '#3e3a3a',
Expand Down
2 changes: 1 addition & 1 deletion example/src/Screens/TabView/CustomIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const styles = StyleSheet.create({
},
badge: {
marginTop: 4,
marginRight: 32,
marginEnd: 32,
backgroundColor: '#f44336',
height: 24,
width: 24,
Expand Down
8 changes: 4 additions & 4 deletions example/src/Screens/TabView/CustomTabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export const CustomTabBar = () => {
styles.tabbar,
{
paddingBottom: insets.bottom,
paddingLeft: insets.left,
paddingRight: insets.right,
paddingStart: insets.left,
paddingEnd: insets.right,
},
]}
>
Expand Down Expand Up @@ -147,8 +147,8 @@ const styles = StyleSheet.create({
activeItem: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
start: 0,
end: 0,
bottom: 0,
},
active: {
Expand Down
24 changes: 12 additions & 12 deletions packages/bottom-tabs/src/views/BottomTabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ export function BottomTabBar({
<Animated.View
style={[
tabBarPosition === 'left'
? styles.left
? styles.start
: tabBarPosition === 'right'
? styles.right
? styles.end
: styles.bottom,
{
backgroundColor:
Expand Down Expand Up @@ -316,8 +316,8 @@ export function BottomTabBar({
: {
paddingTop: insets.top,
paddingBottom: insets.bottom,
paddingLeft: tabBarPosition === 'left' ? insets.left : 0,
paddingRight: tabBarPosition === 'right' ? insets.right : 0,
paddingStart: tabBarPosition === 'left' ? insets.left : 0,
paddingEnd: tabBarPosition === 'right' ? insets.right : 0,
minWidth: hasHorizontalLabels
? getDefaultSidebarWidth(dimensions)
: 0,
Expand Down Expand Up @@ -431,21 +431,21 @@ export function BottomTabBar({
}

const styles = StyleSheet.create({
left: {
start: {
top: 0,
bottom: 0,
left: 0,
borderRightWidth: StyleSheet.hairlineWidth,
start: 0,
borderEndWidth: StyleSheet.hairlineWidth,
},
right: {
end: {
top: 0,
bottom: 0,
right: 0,
borderLeftWidth: StyleSheet.hairlineWidth,
end: 0,
borderStartWidth: StyleSheet.hairlineWidth,
},
bottom: {
left: 0,
right: 0,
start: 0,
end: 0,
bottom: 0,
borderTopWidth: StyleSheet.hairlineWidth,
elevation: 8,
Expand Down
2 changes: 1 addition & 1 deletion packages/bottom-tabs/src/views/BottomTabItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,6 @@ const styles = StyleSheet.create({
},
labelBeside: {
fontSize: 13,
marginLeft: 20,
marginStart: 20,
},
});
8 changes: 4 additions & 4 deletions packages/bottom-tabs/src/views/BottomTabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ export function BottomTabView(props: Props) {
<SafeAreaProviderCompat
style={
tabBarPosition === 'left'
? styles.left
? styles.start
: tabBarPosition === 'right'
? styles.right
? styles.end
: null
}
>
Expand Down Expand Up @@ -306,10 +306,10 @@ export function BottomTabView(props: Props) {
}

const styles = StyleSheet.create({
left: {
start: {
flexDirection: 'row-reverse',
},
right: {
end: {
flexDirection: 'row',
},
screens: {
Expand Down
2 changes: 1 addition & 1 deletion packages/bottom-tabs/src/views/TabBarIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const styles = StyleSheet.create({
},
badge: {
position: 'absolute',
right: -5,
end: -5,
top: -5,
},
});
8 changes: 4 additions & 4 deletions packages/drawer/src/views/DrawerItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export function DrawerItem(props: Props) {
>
<View style={[styles.wrapper, { borderRadius }]}>
{iconNode}
<View style={[styles.label, { marginLeft: iconNode ? 16 : 0 }]}>
<View style={[styles.label, { marginStart: iconNode ? 16 : 0 }]}>
{typeof label === 'string' ? (
<Text
numberOfLines={1}
Expand Down Expand Up @@ -175,11 +175,11 @@ const styles = StyleSheet.create({
flexDirection: 'row',
alignItems: 'center',
paddingVertical: 12,
paddingLeft: 16,
paddingRight: 24,
paddingStart: 16,
paddingEnd: 24,
},
label: {
marginRight: 12,
marginEnd: 12,
marginVertical: 4,
flex: 1,
},
Expand Down
8 changes: 4 additions & 4 deletions packages/drawer/src/views/DrawerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,12 @@ function DrawerViewBase({
drawerType === 'permanent' &&
(drawerPosition === 'left'
? {
borderRightColor: colors.border,
borderRightWidth: StyleSheet.hairlineWidth,
borderEndColor: colors.border,
borderEndWidth: StyleSheet.hairlineWidth,
}
: {
borderLeftColor: colors.border,
borderLeftWidth: StyleSheet.hairlineWidth,
borderStartColor: colors.border,
borderStartWidth: StyleSheet.hairlineWidth,
}),
drawerStyle,
]}
Expand Down
10 changes: 5 additions & 5 deletions packages/elements/src/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export function Header(props: Props) {
<Animated.View
pointerEvents="box-none"
style={[
styles.left,
styles.start,
headerTitleAlign === 'center' && styles.expand,
{ marginStart: insets.left },
leftContainerStyle,
Expand Down Expand Up @@ -270,7 +270,7 @@ export function Header(props: Props) {
insets.right),
},
headerTitleAlign === 'left' && leftButton
? { marginLeft: 4 }
? { marginStart: 4 }
: null,
titleContainerStyle,
]}
Expand All @@ -285,7 +285,7 @@ export function Header(props: Props) {
<Animated.View
pointerEvents="box-none"
style={[
styles.right,
styles.end,
styles.expand,
{ marginEnd: insets.right },
rightContainerStyle,
Expand All @@ -308,11 +308,11 @@ const styles = StyleSheet.create({
marginHorizontal: 16,
justifyContent: 'center',
},
left: {
start: {
justifyContent: 'center',
alignItems: 'flex-start',
},
right: {
end: {
justifyContent: 'center',
alignItems: 'flex-end',
},
Expand Down
8 changes: 4 additions & 4 deletions packages/elements/src/Header/HeaderBackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ const styles = StyleSheet.create({
ios: {
height: 21,
width: 13,
marginLeft: 8,
marginRight: 22,
marginStart: 8,
marginEnd: 22,
marginVertical: 12,
},
default: {
Expand All @@ -216,7 +216,7 @@ const styles = StyleSheet.create({
iconWithLabel:
Platform.OS === 'ios'
? {
marginRight: 6,
marginEnd: 6,
}
: {},
iconMaskContainer: {
Expand All @@ -231,7 +231,7 @@ const styles = StyleSheet.create({
iconMask: {
height: 21,
width: 13,
marginLeft: -14.5,
marginStart: -14.5,
marginVertical: 12,
alignSelf: 'center',
},
Expand Down
75 changes: 75 additions & 0 deletions packages/elements/src/SafeAreaProviderCompat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
} from 'react-native';
import {
initialWindowMetrics,
type Metrics,
SafeAreaFrameContext,
SafeAreaInsetsContext,
SafeAreaProvider,
} from 'react-native-safe-area-context';
Expand Down Expand Up @@ -41,13 +43,86 @@ export function SafeAreaProviderCompat({ children, style }: Props) {
return <View style={[styles.container, style]}>{children}</View>;
}

if (Platform.OS === 'web') {
children = (
<SafeAreaFrameProvider initialMetrics={initialMetrics}>
{children}
</SafeAreaFrameProvider>
);
}

return (
<SafeAreaProvider initialMetrics={initialMetrics} style={style}>
{children}
</SafeAreaProvider>
);
}

// FIXME: On the Web, the safe area frame value doesn't update on resize
// So we workaround this by measuring the frame on resize
const SafeAreaFrameProvider = ({
initialMetrics,
children,
}: {
initialMetrics: Metrics;
children: React.ReactNode;
}) => {
const element = React.useRef<HTMLDivElement>(null);
const [frame, setFrame] = React.useState(initialMetrics.frame);

React.useEffect(() => {
if (element.current == null) {
return;
}

const rect = element.current.getBoundingClientRect();

setFrame({
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height,
});

let timeout: NodeJS.Timeout;

const observer = new ResizeObserver((entries) => {
const entry = entries[0];

if (entry) {
const { x, y, width, height } = entry.contentRect;

// Debounce the frame updates to avoid too many updates in a short time
clearTimeout(timeout);
timeout = setTimeout(() => {
setFrame({ x, y, width, height });
}, 100);
}
});

observer.observe(element.current);

return () => {
observer.disconnect();
clearTimeout(timeout);
};
}, []);

return (
<SafeAreaFrameContext.Provider value={frame}>
<div
ref={element}
style={{
...StyleSheet.absoluteFillObject,
pointerEvents: 'none',
visibility: 'hidden',
}}
/>
{children}
</SafeAreaFrameContext.Provider>
);
};

SafeAreaProviderCompat.initialMetrics = initialMetrics;

const styles = StyleSheet.create({
Expand Down
Loading

0 comments on commit 5104ced

Please sign in to comment.