@momo-kits/foundation 0.165.2-beta.3 → 0.167.1-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,11 +58,13 @@ export default function BottomTabBar({
58
58
  const { theme } = useContext(ApplicationContext);
59
59
  const { routes } = state;
60
60
  const widthDevice = useWindowDimensions()?.width;
61
+ const insets = useSafeAreaInsets();
61
62
  const useFloating = floatingButton && state.routes.length % 2 === 0;
62
- const itemWidth = widthDevice / (state.routes.length + (useFloating ? 1 : 0));
63
+ const itemWidth =
64
+ (widthDevice - insets.left - insets.right) /
65
+ (state.routes.length + (useFloating ? 1 : 0));
63
66
  // const buildLink = useLinkBuilder();
64
67
  const indicatorAnimated = useSharedValue(0);
65
- const insets = useSafeAreaInsets();
66
68
 
67
69
  const indicatorStyle = useAnimatedStyle(() => ({
68
70
  width: itemWidth,
@@ -246,7 +248,8 @@ export default function BottomTabBar({
246
248
  },
247
249
  {
248
250
  paddingBottom: paddingBottom,
249
- paddingHorizontal: Math.max(insets.left, insets.right),
251
+ paddingLeft: insets.left,
252
+ paddingRight: insets.right,
250
253
  },
251
254
  style,
252
255
  ]}
@@ -1,6 +1,6 @@
1
1
  import React, { Ref, useContext } from 'react';
2
2
  import LinearGradient from 'react-native-linear-gradient';
3
- import { Dimensions, Platform, StyleSheet, View } from 'react-native';
3
+ import { Platform, StyleSheet, View } from 'react-native';
4
4
  import Animated, {
5
5
  Extrapolation,
6
6
  interpolate,
@@ -18,12 +18,11 @@ import {
18
18
  AnimatedCompatValue,
19
19
  useNormalizedSharedValue,
20
20
  } from '../utils';
21
+ import { useHorizontalLayout } from '../../Layout/utils';
21
22
 
22
23
  const SCREEN_PADDING = 12;
23
24
  const BACK_WIDTH = 28;
24
25
 
25
- const { width: screenWidth } = Dimensions.get('window');
26
-
27
26
  const HeaderExtendHeader: React.FC<{
28
27
  headerType?: HeaderType;
29
28
  animatedValue: AnimatedCompatValue;
@@ -52,6 +51,8 @@ const HeaderExtendHeader: React.FC<{
52
51
  const gradientColor = customGradientColor ?? theme.colors.gradient;
53
52
  const headerBackground = customBackground ?? theme.assets?.headerBackground;
54
53
  const leftPosition = inputSearchProps?.leftPosition || BACK_WIDTH + 20;
54
+ const layout = useHorizontalLayout(SCREEN_PADDING);
55
+ const { insets } = layout;
55
56
 
56
57
  let useShadowHeader = useShadowHeaderProp;
57
58
  if (inputSearchProps && Platform.OS === 'android') {
@@ -79,7 +80,7 @@ const HeaderExtendHeader: React.FC<{
79
80
  translateX: interpolate(
80
81
  sharedValue.value,
81
82
  [0, 100],
82
- [SCREEN_PADDING, leftPosition],
83
+ [layout.marginLeft, leftPosition + insets.left],
83
84
  Extrapolation.CLAMP,
84
85
  ),
85
86
  },
@@ -88,8 +89,8 @@ const HeaderExtendHeader: React.FC<{
88
89
  sharedValue.value,
89
90
  [0, 100],
90
91
  [
91
- screenWidth - SCREEN_PADDING * 2,
92
- screenWidth - leftPosition - 12 - headerRightWidth,
92
+ layout.width,
93
+ layout.width + SCREEN_PADDING - leftPosition - headerRightWidth,
93
94
  ],
94
95
  Extrapolation.CLAMP,
95
96
  ),
@@ -1,17 +1,13 @@
1
1
  import { Colors, Radius, Spacing, Styles } from '../../Consts';
2
2
  import { InputRef, InputSearch } from '../../Input';
3
- import {
4
- Dimensions,
5
- StyleSheet,
6
- TouchableOpacity,
7
- View,
8
- } from 'react-native';
3
+ import { StyleSheet, TouchableOpacity, View } from 'react-native';
9
4
  import Animated, { useAnimatedStyle } from 'react-native-reanimated';
10
5
  import React, { useContext } from 'react';
11
6
  import { SearchHeaderProps } from '../types';
12
7
  import { ApplicationContext, MiniAppContext } from '../../Context';
13
8
  import { Text } from '../../Text';
14
9
  import { useNormalizedSharedValue } from '../utils';
10
+ import { useHorizontalLayout } from '../../Layout/utils';
15
11
 
16
12
  const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
17
13
  (
@@ -27,7 +23,7 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
27
23
  const { theme, navigator } = useContext(ApplicationContext);
28
24
  const context = useContext<any>(MiniAppContext);
29
25
  const BACK_WIDTH = 28;
30
- const { width: screenWidth } = Dimensions.get('window');
26
+ const { width: safeWidth } = useHorizontalLayout(0);
31
27
 
32
28
  const sharedValue = useNormalizedSharedValue(animatedValue);
33
29
  const leftPosition = props?.leftPosition ?? BACK_WIDTH + 20;
@@ -77,7 +73,7 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
77
73
  style={[
78
74
  Styles.flex,
79
75
  renderButtons && {
80
- maxWidth: screenWidth - leftPosition - 12 - headerRightWidth,
76
+ maxWidth: safeWidth - leftPosition - 12 - headerRightWidth,
81
77
  },
82
78
  ]}
83
79
  >
package/Layout/Card.tsx CHANGED
@@ -1,6 +1,6 @@
1
1
  import React, { useContext } from 'react';
2
- import { Dimensions, View, ViewProps } from 'react-native';
3
- import { useGridSystem } from './utils';
2
+ import { View, ViewProps } from 'react-native';
3
+ import { useGridSystem, useHorizontalLayout } from './utils';
4
4
  import { GridContextProps } from './types';
5
5
  import { GridContext, GridSystem } from './index';
6
6
  import { Image } from '../Image';
@@ -32,7 +32,8 @@ const Card: React.FC<CardProps> = ({
32
32
 
33
33
  const gutterSize = 8;
34
34
  const margin = 12;
35
- const widthSection = Dimensions.get('window').width - margin * 2;
35
+ const layout = useHorizontalLayout(margin);
36
+ const widthSection = layout.width;
36
37
  let sizePerSpan =
37
38
  (widthSection - margin * 2 - gutterSize * (numberOfColumns - 1)) /
38
39
  numberOfColumns -
@@ -76,7 +77,8 @@ const Card: React.FC<CardProps> = ({
76
77
  styles.card,
77
78
  {
78
79
  width: widthSection,
79
- marginHorizontal: margin,
80
+ marginLeft: layout.marginLeft,
81
+ marginRight: layout.marginRight,
80
82
  gap: gutterSize,
81
83
  },
82
84
  !!backgroundImage && { backgroundColor: undefined },
@@ -19,6 +19,7 @@ import {
19
19
  AnimatedCompatValue,
20
20
  useNormalizedSharedValue,
21
21
  } from '../Application/utils';
22
+ import { useHorizontalLayout } from './utils';
22
23
 
23
24
  export interface FloatingButtonProps {
24
25
  label?: string;
@@ -56,6 +57,7 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
56
57
  const lastOffset = useSharedValue(0);
57
58
  const lastDirection = useSharedValue<string | null>(null);
58
59
  const [showText, setShowText] = useState(true);
60
+ const { marginRight } = useHorizontalLayout(12);
59
61
 
60
62
  useEffect(() => {
61
63
  if (!label) return;
@@ -119,7 +121,7 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
119
121
  style={[
120
122
  styles.container,
121
123
  {
122
- right: position === 'right' ? 12 : undefined,
124
+ right: position === 'right' ? marginRight : undefined,
123
125
  alignSelf: position === 'center' ? 'center' : 'flex-end',
124
126
  bottom,
125
127
  },
@@ -136,7 +138,7 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
136
138
  style={[
137
139
  styles.container,
138
140
  {
139
- right: position === 'right' ? 12 : undefined,
141
+ right: position === 'right' ? marginRight : undefined,
140
142
  alignSelf: position === 'center' ? 'center' : 'flex-end',
141
143
  height: size === 'small' ? 36 : 48,
142
144
  backgroundColor: theme.colors.primary,
@@ -1,6 +1,6 @@
1
1
  import React, { useContext } from 'react';
2
- import { Dimensions, View, ViewProps } from 'react-native';
3
- import { useGridSystem } from './utils';
2
+ import { useWindowDimensions, View, ViewProps } from 'react-native';
3
+ import { useGridSystem, useHorizontalLayout } from './utils';
4
4
  import { GridContextProps } from './types';
5
5
  import { GridContext } from './index';
6
6
  import { ApplicationContext, MiniAppContext } from '../Context';
@@ -38,14 +38,9 @@ const Section: React.FC<SectionProps> = ({
38
38
  const { numberOfColumns } = useGridSystem();
39
39
 
40
40
  const gutterSize = 12;
41
- let margin = 0;
42
- if (useMargin) {
43
- margin = 12;
44
- }
45
- let widthSection = Dimensions.get('window').width;
46
- if (useMargin) {
47
- widthSection = widthSection - margin * 2;
48
- }
41
+ const layout = useHorizontalLayout(12);
42
+ const { width: windowWidth } = useWindowDimensions();
43
+ const widthSection = useMargin ? layout.width : windowWidth;
49
44
 
50
45
  const sizePerSpan =
51
46
  (widthSection - gutterSize * (numberOfColumns - 1)) / numberOfColumns -
@@ -77,7 +72,8 @@ const Section: React.FC<SectionProps> = ({
77
72
  styles.protectedStyle,
78
73
  {
79
74
  width: widthSection,
80
- marginHorizontal: margin,
75
+ marginLeft: useMargin ? layout.marginLeft : 0,
76
+ marginRight: useMargin ? layout.marginRight : 0,
81
77
  flexDirection: 'row',
82
78
  flexWrap: 'wrap',
83
79
  gap: gutterSize,
package/Layout/utils.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import React, { Fragment, ReactElement } from 'react';
2
2
  import { useWindowDimensions } from 'react-native';
3
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
3
4
 
4
5
  /**
5
6
  * validate children type
@@ -44,4 +45,18 @@ const useGridSystem = () => {
44
45
  return { numberOfColumns };
45
46
  };
46
47
 
47
- export { useGridSystem, validateChildren };
48
+ // Side insets are 0 on portrait iPhones; iPhone Duo and landscape report them
49
+ const useHorizontalLayout = (margin: number) => {
50
+ const { width } = useWindowDimensions();
51
+ const insets = useSafeAreaInsets();
52
+ const marginLeft = margin + insets.left;
53
+ const marginRight = margin + insets.right;
54
+ return {
55
+ marginLeft,
56
+ marginRight,
57
+ width: width - marginLeft - marginRight,
58
+ insets,
59
+ };
60
+ };
61
+
62
+ export { useGridSystem, useHorizontalLayout, validateChildren };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.165.2-beta.3",
3
+ "version": "0.167.1-beta.2",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},