@momo-kits/foundation 0.169.4-beta.2 → 0.169.4-beta.3

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.
@@ -17,7 +17,7 @@ import { CurvedContainer } from './CurvedContainer';
17
17
  import { ActiveIndicator } from './ActiveIndicator';
18
18
  import { getHorizontalBarWidth, TabBarMetrics, TabBarMotion } from './metrics';
19
19
  import { getTabItems, TabItem } from './tabItems';
20
- import { CappedScaleText } from './TabBarIcon';
20
+ import { FixedScaleText } from './TabBarIcon';
21
21
  import { styles } from './BottomTabBar.styles';
22
22
 
23
23
  type Props = BottomTabBarProps & {
@@ -114,7 +114,7 @@ const CenterAction: React.FC<{
114
114
  </Animated.View>
115
115
  <View style={styles.ctaLabel}>
116
116
  {fixedFontScale ? (
117
- <CappedScaleText>{labelText}</CappedScaleText>
117
+ <FixedScaleText>{labelText}</FixedScaleText>
118
118
  ) : (
119
119
  labelText
120
120
  )}
@@ -194,17 +194,21 @@ const HorizontalTabBar: React.FC<{
194
194
  return renderItems(items);
195
195
  };
196
196
 
197
+ const customContainer = withCta && floatingButton?.container;
198
+
197
199
  return (
198
200
  <View
199
201
  style={[styles.container, { width }]}
200
202
  accessibilityLabel={'bottom_tab_bar'}
201
203
  >
202
- <CurvedContainer
203
- width={width}
204
- height={TabBarMetrics.height}
205
- radius={TabBarMetrics.height / 2}
206
- notchCenterX={withCta ? width / 2 : undefined}
207
- />
204
+ {customContainer || (
205
+ <CurvedContainer
206
+ width={width}
207
+ height={TabBarMetrics.height}
208
+ radius={TabBarMetrics.height / 2}
209
+ notchCenterX={withCta ? width / 2 : undefined}
210
+ />
211
+ )}
208
212
  <View style={styles.content}>
209
213
  <ActiveIndicator
210
214
  axis={'x'}
@@ -254,7 +258,6 @@ export default function BottomTabBar(props: Props) {
254
258
  ]}
255
259
  >
256
260
  <HorizontalTabBar
257
- fixedFontScale
258
261
  items={getTabItems(props)}
259
262
  width={width}
260
263
  floatingButton={floatingButton}
@@ -10,7 +10,7 @@ import Animated, {
10
10
  useSharedValue,
11
11
  withTiming,
12
12
  } from 'react-native-reanimated';
13
- import { CappedScaleText, TabBarIcon } from './TabBarIcon';
13
+ import { FixedScaleText, TabBarIcon } from './TabBarIcon';
14
14
  import { Text } from '../../Text';
15
15
  import { MiniAppContext } from '../../Context';
16
16
  import { Colors, Spacing } from '../../Consts';
@@ -98,7 +98,7 @@ const TabItemContent: React.FC<TabItemContentProps> = ({
98
98
  />
99
99
  </View>
100
100
  {!hideLabel &&
101
- (fixedFontScale ? <CappedScaleText>{text}</CappedScaleText> : text)}
101
+ (fixedFontScale ? <FixedScaleText>{text}</FixedScaleText> : text)}
102
102
  </>
103
103
  );
104
104
  };
@@ -166,11 +166,6 @@ const styles = StyleSheet.create({
166
166
  },
167
167
  labelBox: {
168
168
  alignSelf: 'stretch',
169
- // fixed to the design line height so a capped-scale label overflows downward and the
170
- // icon above it stays put
171
- height: TabBarMetrics.labelHeight,
172
- justifyContent: 'flex-start',
173
- overflow: 'visible',
174
169
  },
175
170
  label: {
176
171
  textAlign: 'center',
@@ -13,7 +13,7 @@ import { TabItemContent } from './CustomBottomTabItem';
13
13
  import { CurvedContainer } from './CurvedContainer';
14
14
  import { TabBarMetrics } from './metrics';
15
15
  import { getTabItems, TabItem } from './tabItems';
16
- import { CappedScaleText } from './TabBarIcon';
16
+ import { FixedScaleText } from './TabBarIcon';
17
17
  import { usePressLift } from './usePressLift';
18
18
  import { ActiveIndicator } from './ActiveIndicator';
19
19
  import {
@@ -116,7 +116,7 @@ const RailCenterAction: React.FC<{ floatingButton: FloatingButtonProps }> = ({
116
116
  <CtaIcon icon={floatingButton.icon} />
117
117
  </Animated.View>
118
118
  <View style={styles.railCtaLabel}>
119
- <CappedScaleText>
119
+ <FixedScaleText>
120
120
  <Text
121
121
  numberOfLines={1}
122
122
  typography={'label_xs_medium'}
@@ -124,7 +124,7 @@ const RailCenterAction: React.FC<{ floatingButton: FloatingButtonProps }> = ({
124
124
  >
125
125
  {floatingButton.label}
126
126
  </Text>
127
- </CappedScaleText>
127
+ </FixedScaleText>
128
128
  {floatingButton.labelContent && (
129
129
  <View pointerEvents={'none'} style={styles.railCtaLabelOverlay}>
130
130
  {floatingButton.labelContent}
@@ -71,30 +71,6 @@ export const FixedScaleText: React.FC<{ children: React.ReactNode }> = ({
71
71
  );
72
72
  };
73
73
 
74
- // the tab labels follow the OS/host font scale but never grow past this, so the fixed-height
75
- // container and the notch stay aligned
76
- const TAB_LABEL_MAX_SCALE = 1.2;
77
-
78
- /**
79
- * caps the label scale at `TAB_LABEL_MAX_SCALE`: it keeps following the host/OS font scale but
80
- * stops growing past 1.2× so it fits the fixed bar geometry
81
- */
82
- export const CappedScaleText: React.FC<{ children: React.ReactNode }> = ({
83
- children,
84
- }) => {
85
- const context = useContext<any>(MiniAppContext);
86
- return (
87
- <MiniAppContext.Provider
88
- value={{
89
- ...context,
90
- fontScale: { ...context?.fontScale, maxScaleRate: TAB_LABEL_MAX_SCALE },
91
- }}
92
- >
93
- {children}
94
- </MiniAppContext.Provider>
95
- );
96
- };
97
-
98
74
  /**
99
75
  * numbers use the error color, text the warning color (Figma Badge round numeric / text)
100
76
  */
@@ -20,9 +20,6 @@ const TabBarMetrics = {
20
20
  indicatorPaddingHorizontal: Spacing.M,
21
21
  indicatorRadius: Radius.XL,
22
22
  indicatorHeight: 32,
23
- // label_s_medium line height: the label box keeps this height so a scaled label grows
24
- // downward instead of pushing the icon up
25
- labelHeight: 18,
26
23
  // home indicator / gesture bar area under the container
27
24
  systemIndicatorHeight: 24,
28
25
  // unfolded foldables (short side from 600, the smallest in the spec) use 65% of the short
@@ -36,6 +36,7 @@ export type BottomTabProps = {
36
36
  };
37
37
 
38
38
  export type FloatingButtonProps = {
39
+ container?: React.ReactNode;
39
40
  icon: string | React.ReactNode;
40
41
  label: string;
41
42
  onPress: () => void;
@@ -13,7 +13,7 @@ import Animated, {
13
13
  } from 'react-native-reanimated';
14
14
  import { scheduleOnRN } from 'react-native-worklets';
15
15
  import { ApplicationContext } from '../Context';
16
- import { Colors } from '../Consts';
16
+ import { Colors, Spacing } from '../Consts';
17
17
  import { Icon } from '../Icon';
18
18
  import { useScaleSize, exportFontFamily } from '../Text';
19
19
  import { type AnimatedCompatValue } from '../Application/utils';
@@ -50,8 +50,11 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
50
50
  const labelFontFamily = exportFontFamily('bold');
51
51
  const maxWidth = useSharedValue(0);
52
52
  const minWidth = size === 'small' ? 36 : 48;
53
+ const iconSize = size === 'small' ? 12 : 24;
53
54
  const opacityAnimated = useSharedValue(0);
54
55
  const widthAnimated = useSharedValue<number | null>(null);
56
+ const paddingLeftAnimated = useSharedValue(Spacing.M);
57
+ const collapsedPaddingLeft = useSharedValue(Spacing.M);
55
58
  const lastOffset = useSharedValue(0);
56
59
  const lastDirection = useSharedValue<string | null>(null);
57
60
  const [showText, setShowText] = useState(true);
@@ -73,6 +76,9 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
73
76
  lastDirection.value = direction;
74
77
  if (direction === 'down') {
75
78
  opacityAnimated.value = withTiming(0, { duration: 100 });
79
+ paddingLeftAnimated.value = withTiming(collapsedPaddingLeft.value, {
80
+ duration: 100,
81
+ });
76
82
  widthAnimated.value = withTiming(
77
83
  minWidth,
78
84
  { duration: 100 },
@@ -82,6 +88,7 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
82
88
  );
83
89
  } else {
84
90
  opacityAnimated.value = withTiming(1, { duration: 100 });
91
+ paddingLeftAnimated.value = withTiming(Spacing.M, { duration: 100 });
85
92
  widthAnimated.value = withTiming(
86
93
  maxWidth.value,
87
94
  { duration: 100 },
@@ -98,6 +105,7 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
98
105
 
99
106
  const containerStyle = useAnimatedStyle(() => ({
100
107
  width: widthAnimated.value ?? undefined,
108
+ paddingLeft: paddingLeftAnimated.value,
101
109
  }));
102
110
 
103
111
  const labelStyle = useAnimatedStyle(() => ({
@@ -107,8 +115,14 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
107
115
  const handleLayout = (event: LayoutChangeEvent) => {
108
116
  const layout = event.nativeEvent.layout;
109
117
  if (widthAnimated.value != null) return;
110
- maxWidth.value = layout.width;
111
- widthAnimated.value = layout.width;
118
+ // layout is already scaled: rescale by height/minWidth so `width` isn't scaled twice
119
+ const expandedWidth = (layout.width * minWidth) / layout.height;
120
+ maxWidth.value = expandedWidth;
121
+ widthAnimated.value = expandedWidth;
122
+ // collapsed it is a circle as wide as it is tall: center the icon from the
123
+ // rendered height so it stays centered when sizes are scaled but padding is not
124
+ collapsedPaddingLeft.value =
125
+ (layout.height - (layout.height * iconSize) / minWidth) / 2;
112
126
  };
113
127
 
114
128
  if (renderComponent) {
@@ -140,11 +154,7 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
140
154
  ]}
141
155
  >
142
156
  <TouchableOpacity style={styles.content} onPress={onPress}>
143
- <Icon
144
- source={icon}
145
- size={size === 'small' ? 12 : 24}
146
- color={iconColor}
147
- />
157
+ <Icon source={icon} size={iconSize} color={iconColor} />
148
158
  {showText && !!label && (
149
159
  <Animated.Text
150
160
  allowFontScaling={false}
package/Text/utils.ts CHANGED
@@ -9,18 +9,13 @@ const MAX_DEVICE_SCALE = 5;
9
9
  const useScaleSize = (size: number, scaleRate?: number) => {
10
10
  const { width } = useWindowDimensions();
11
11
  const context = useContext<any>(MiniAppContext);
12
- // opt-in ceiling: when set (arg or context), the final size never exceeds size × capRate,
13
- // in both the mini-app userScaleRate path and the OS path. Undefined keeps the old behavior.
14
- const capRate = scaleRate ?? context?.fontScale?.maxScaleRate;
15
- const cap = (scaled: number) =>
16
- capRate != null ? Math.min(scaled, size * capRate) : scaled;
17
12
  if (context?.fontScale?.useOSScaleRate === false) {
18
- return cap(size * (context.fontScale.userScaleRate ?? 1));
13
+ return size * (context.fontScale.userScaleRate ?? 1);
19
14
  }
20
15
  const fontScale = PixelRatio.getFontScale();
21
16
  const deviceScale = width / DEFAULT_SCREEN_SIZE;
22
17
 
23
- const maxScaleRate = capRate ?? MAX_FONT_SCALE;
18
+ const maxScaleRate = scaleRate ?? MAX_FONT_SCALE;
24
19
 
25
20
  let fontSizeDeviceScale = size;
26
21
  let fontSizeOSScale = size;
@@ -39,7 +34,7 @@ const useScaleSize = (size: number, scaleRate?: number) => {
39
34
  );
40
35
  }
41
36
 
42
- return cap(Math.max(fontSizeDeviceScale, fontSizeOSScale));
37
+ return Math.max(fontSizeDeviceScale, fontSizeOSScale);
43
38
  };
44
39
 
45
40
  const scaleSize = (size: number) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.169.4-beta.2",
3
+ "version": "0.169.4-beta.3",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},