@zhenryx/react-native-components 0.0.2 → 0.1.0

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.
@@ -1,7 +1,6 @@
1
1
  import React from 'react';
2
2
  import { TextStyle } from 'react-native';
3
3
  export interface DialogProps {
4
- useModal?: boolean;
5
4
  visible: boolean;
6
5
  type?: 'alert' | 'confirm';
7
6
  title?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../../src/components/Dialog/Dialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAA+B,SAAS,EAAE,MAAM,cAAc,CAAC;AAItE,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B;AACD,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAoDxC,CAAC"}
1
+ {"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../../src/components/Dialog/Dialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAA+B,SAAS,EAAE,MAAM,cAAc,CAAC;AAItE,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B;AACD,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAkDxC,CAAC"}
@@ -9,7 +9,7 @@ const react_native_1 = require("react-native");
9
9
  const Text_1 = require("../Text/Text");
10
10
  const ThemeConfig_1 = require("../ThemeConfig/ThemeConfig");
11
11
  const Popup_1 = require("../Popup/Popup");
12
- const Dialog = ({ useModal = true, visible = false, type = "alert", title = "提示", content, titleStyle, contentStyle, closeOnOverlayPress = false, round = false, confirmText = "确认", cancelText = '取消', onConfirm = () => null, onCancel = () => null, children }) => {
12
+ const Dialog = ({ visible = false, type = "alert", title = "提示", content, titleStyle, contentStyle, closeOnOverlayPress = false, round = false, confirmText = "确认", cancelText = '取消', onConfirm = () => null, onCancel = () => null, children }) => {
13
13
  const { theme } = (0, ThemeConfig_1.useTheme)();
14
14
  const confirmTextColor = theme['$primary-color'] || '#e25829ff';
15
15
  const paddingHorizontal = theme['$dialog-padding-horizontal'] || 20;
@@ -32,7 +32,7 @@ const Dialog = ({ useModal = true, visible = false, type = "alert", title = "提
32
32
  <react_native_1.Pressable style={styles.dialog_footer_button_confirm} onPress={handleConfirm}><Text_1.Text style={[styles.dialog_footer_button_confirm_text, { color: confirmTextColor }]}>{confirmText}</Text_1.Text></react_native_1.Pressable>
33
33
  </react_native_1.View>
34
34
  </react_native_1.View>);
35
- return (<Popup_1.Popup useModal={useModal} visible={visible} closeable={false} closeOnOverlayPress={closeOnOverlayPress} onClose={handleClose} round={round}>
35
+ return (<Popup_1.Popup visible={visible} closeable={false} closeOnOverlayPress={closeOnOverlayPress} onClose={handleClose} round={round}>
36
36
  {renderDialog()}
37
37
  </Popup_1.Popup>);
38
38
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Header.d.ts","sourceRoot":"","sources":["../../src/components/Header/Header.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAW,SAAS,EAAE,MAAM,OAAO,CAAA;AACjD,OAAO,EAAQ,SAAS,EAAE,SAAS,EAAE,SAAS,EAAgC,MAAM,cAAc,CAAA;AAIlG,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,SAAS,CAAC;IAC1B,eAAe,CAAC,EAAE,SAAS,CAAC;IAC5B,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,cAAc,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACtC,UAAU,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAsDxC,CAAA"}
1
+ {"version":3,"file":"Header.d.ts","sourceRoot":"","sources":["../../src/components/Header/Header.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAW,SAAS,EAAE,MAAM,OAAO,CAAA;AACjD,OAAO,EAAQ,SAAS,EAAE,SAAS,EAAE,SAAS,EAAgC,MAAM,cAAc,CAAA;AAKlG,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,SAAS,CAAC;IAC1B,eAAe,CAAC,EAAE,SAAS,CAAC;IAC5B,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,cAAc,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACtC,UAAU,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAwDxC,CAAA"}
@@ -26,18 +26,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Header = void 0;
27
27
  const react_1 = __importStar(require("react"));
28
28
  const react_native_1 = require("react-native");
29
+ const react_native_safe_area_context_1 = require("react-native-safe-area-context");
29
30
  const Text_1 = require("../Text/Text");
30
31
  const ThemeConfig_1 = require("../ThemeConfig/ThemeConfig");
31
32
  const Header = ({ title = '自定义头部导航', backGroundColor, leftComponent, centerComponent, rightComponent, containerStyle, titleStyle: customTitleStyle, showBack = true, onBack }) => {
32
33
  const { theme } = (0, ThemeConfig_1.useTheme)();
34
+ const insets = (0, react_native_safe_area_context_1.useSafeAreaInsets)();
33
35
  const headerStyle = (0, react_1.useMemo)(() => ({
34
- height: theme['$header-height'] || 44,
36
+ height: (theme['$header-height'] || 44) + insets.top,
37
+ paddingTop: insets.top,
35
38
  backgroundColor: backGroundColor || theme['$header-background'] || 'transparent',
36
39
  flexDirection: 'row',
37
40
  justifyContent: 'space-between',
38
41
  alignItems: 'center',
39
42
  paddingHorizontal: theme['$header-spacing'] || 15,
40
- }), [theme, backGroundColor]);
43
+ }), [theme, backGroundColor, insets.top]);
41
44
  const defaultTitleStyle = (0, react_1.useMemo)(() => ({
42
45
  fontSize: theme['$header-title-fontsize'] || 18,
43
46
  fontWeight: theme['$header-title-fontweight'] || '500'
@@ -1,11 +1,10 @@
1
- import React from "react";
2
- import { StyleProp, ViewStyle } from "react-native";
1
+ import React from 'react';
2
+ import { StyleProp, ViewStyle } from 'react-native';
3
3
  export interface OverLayProps {
4
- useModal?: boolean;
5
4
  children?: React.ReactNode;
6
5
  visible: boolean;
7
6
  overlayStyle?: StyleProp<ViewStyle>;
8
- onOverlayPress?(): void;
7
+ onOverlayPress?: () => void;
9
8
  }
10
9
  export declare const OverLay: React.FC<OverLayProps>;
11
10
  //# sourceMappingURL=Overlay.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Overlay.d.ts","sourceRoot":"","sources":["../../src/components/Overlay/Overlay.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AAEpE,OAAO,EAGL,SAAS,EACT,SAAS,EAIV,MAAM,cAAc,CAAC;AACtB,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACpC,cAAc,CAAC,IAAI,IAAI,CAAC;CACzB;AAGD,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAgF1C,CAAC"}
1
+ {"version":3,"file":"Overlay.d.ts","sourceRoot":"","sources":["../../src/components/Overlay/Overlay.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAC3D,OAAO,EAKL,SAAS,EACT,SAAS,EAEV,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACpC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AACD,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CA8C1C,CAAC"}
@@ -25,68 +25,47 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.OverLay = void 0;
27
27
  const react_1 = __importStar(require("react"));
28
- const ThemeConfig_1 = require("../ThemeConfig/ThemeConfig");
29
28
  const react_native_1 = require("react-native");
30
- const OverLay = ({ useModal = true, children, visible = false, overlayStyle, onOverlayPress, }) => {
29
+ const ThemeConfig_1 = require("../ThemeConfig/ThemeConfig");
30
+ const OverLay = ({ children, visible, overlayStyle, onOverlayPress, }) => {
31
31
  const { theme } = (0, ThemeConfig_1.useTheme)();
32
- const [realVisible, setRealVisible] = (0, react_1.useState)(visible);
33
- const opacityAnim = (0, react_1.useRef)(new react_native_1.Animated.Value(visible ? 1 : 0)).current;
34
- const fadeInstance = (0, react_1.useRef)(null);
32
+ const [mounted, setMounted] = (0, react_1.useState)(visible);
33
+ const opacity = (0, react_1.useRef)(new react_native_1.Animated.Value(visible ? 1 : 0)).current;
35
34
  (0, react_1.useEffect)(() => {
36
35
  if (visible) {
37
- setRealVisible(true);
38
- }
39
- if (fadeInstance.current) {
40
- fadeInstance.current.stop();
36
+ setMounted(true);
41
37
  }
42
- fadeInstance.current = react_native_1.Animated.timing(opacityAnim, {
38
+ react_native_1.Animated.timing(opacity, {
43
39
  toValue: visible ? 1 : 0,
44
40
  duration: 250,
41
+ easing: react_native_1.Easing.out(react_native_1.Easing.cubic),
45
42
  useNativeDriver: true,
46
- });
47
- fadeInstance.current.start(({ finished }) => {
48
- if (finished && fadeInstance.current) {
49
- fadeInstance.current = null;
50
- if (!visible) {
51
- setRealVisible(false);
52
- }
43
+ }).start(({ finished }) => {
44
+ if (finished && !visible) {
45
+ setMounted(false);
53
46
  }
54
47
  });
55
- return () => {
56
- if (fadeInstance.current) {
57
- fadeInstance.current.stop();
58
- fadeInstance.current = null;
59
- }
60
- };
61
- }, [visible]);
62
- const dynamicBg = theme['$overlay-bg-color'] || 'rgba(0, 0, 0, 0.35)';
63
- const containerStyle = (0, react_1.useMemo)(() => [
64
- styles.container,
65
- { backgroundColor: dynamicBg, opacity: opacityAnim },
66
- overlayStyle,
67
- ], [dynamicBg, opacityAnim, overlayStyle]);
68
- const renderContent = () => (<react_native_1.Animated.View style={containerStyle}>
48
+ }, [visible, opacity]);
49
+ if (!mounted)
50
+ return null;
51
+ return (<react_native_1.Animated.View style={[
52
+ react_native_1.StyleSheet.absoluteFill,
53
+ { backgroundColor: theme['$overlay-bg-color'] ?? 'rgba(0,0,0,0.35)' },
54
+ { opacity },
55
+ overlayStyle,
56
+ ]}>
69
57
  {onOverlayPress && (<react_native_1.Pressable style={react_native_1.StyleSheet.absoluteFill} onPress={onOverlayPress}/>)}
70
58
  <react_native_1.View style={styles.content} pointerEvents="box-none">
71
59
  {children}
72
60
  </react_native_1.View>
73
61
  </react_native_1.Animated.View>);
74
- if (useModal) {
75
- return (<react_native_1.Modal visible={realVisible} transparent animationType='none' statusBarTranslucent onRequestClose={onOverlayPress}>
76
- {renderContent()}
77
- </react_native_1.Modal>);
78
- }
79
- return realVisible ? renderContent() : null;
80
62
  };
81
63
  exports.OverLay = OverLay;
64
+ exports.OverLay.displayName = 'OverLay';
82
65
  const styles = react_native_1.StyleSheet.create({
83
- container: {
84
- ...react_native_1.StyleSheet.absoluteFillObject,
85
- },
86
66
  content: {
87
67
  flex: 1,
88
68
  alignItems: 'center',
89
69
  justifyContent: 'center',
90
- }
70
+ },
91
71
  });
92
- exports.OverLay.displayName = 'OverLay';
@@ -1,7 +1,6 @@
1
- import React from "react";
2
- import { StyleProp, ViewStyle } from "react-native";
1
+ import React from 'react';
2
+ import { StyleProp, ViewStyle } from 'react-native';
3
3
  export interface PopupProps {
4
- useModal?: boolean;
5
4
  visible?: boolean;
6
5
  position?: 'bottom' | 'center' | 'top';
7
6
  height?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"Popup.d.ts","sourceRoot":"","sources":["../../src/components/Popup/Popup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAKN,MAAM,OAAO,CAAC;AAEf,OAAO,EAGL,SAAS,EACT,SAAS,EAGV,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,YAAY,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACpC,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAID,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,UAAU,CA2JtC,CAAC"}
1
+ {"version":3,"file":"Popup.d.ts","sourceRoot":"","sources":["../../src/components/Popup/Popup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAC3D,OAAO,EAGL,SAAS,EACT,SAAS,EAGV,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,YAAY,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACpC,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,UAAU,CAuHtC,CAAC"}
@@ -25,117 +25,95 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Popup = void 0;
27
27
  const react_1 = __importStar(require("react"));
28
- const Overlay_1 = require("../Overlay/Overlay");
29
28
  const react_native_1 = require("react-native");
29
+ const Overlay_1 = require("../Overlay/Overlay");
30
30
  const ThemeConfig_1 = require("../ThemeConfig/ThemeConfig");
31
- const ANIMATION_DURATION = 250;
32
- const Popup = (props) => {
33
- const { useModal = true, visible = false, position = 'center', height, width, round = false, closeable = false, closeOnOverlayPress = false, overlayStyle, style, children, onClose, } = props;
31
+ const DURATION = 250;
32
+ const Popup = ({ visible = false, position = 'center', height, width, round = false, closeable = false, closeOnOverlayPress = false, overlayStyle, style, children, onClose, }) => {
34
33
  const { theme } = (0, ThemeConfig_1.useTheme)();
35
34
  const radius = theme['$popup-border-radius'] ?? 10;
36
35
  const minHeight = theme['$popup-height'] ?? 100;
37
- const closeIconWidth = theme['$popup-closeicon-width'] ?? 12;
38
- const closeIconHeight = theme['$popup-closeicon-height'] ?? 12;
39
- const centerPopRadius = theme['$popup-center-border-radius'] || 10;
40
- const animatedValue = (0, react_1.useRef)(new react_native_1.Animated.Value(0)).current;
41
- const fadeInstance = (0, react_1.useRef)(null);
42
- const [realVisible, setRealVisible] = (0, react_1.useState)(visible);
36
+ const centerRadius = theme['$popup-center-border-radius'] ?? 10;
37
+ const closeIconSize = {
38
+ width: theme['$popup-closeicon-width'] ?? 12,
39
+ height: theme['$popup-closeicon-height'] ?? 12,
40
+ };
41
+ const progress = (0, react_1.useRef)(new react_native_1.Animated.Value(visible ? 1 : 0)).current;
42
+ const [mounted, setMounted] = (0, react_1.useState)(visible);
43
43
  (0, react_1.useEffect)(() => {
44
- if (visible) {
45
- setRealVisible(true);
46
- }
47
- if (fadeInstance.current) {
48
- fadeInstance.current.stop();
49
- }
50
- fadeInstance.current = react_native_1.Animated.timing(animatedValue, {
44
+ if (visible)
45
+ setMounted(true);
46
+ react_native_1.Animated.timing(progress, {
51
47
  toValue: visible ? 1 : 0,
52
- duration: ANIMATION_DURATION,
53
- easing: visible ? react_native_1.Easing.out(react_native_1.Easing.cubic) : react_native_1.Easing.in(react_native_1.Easing.cubic),
48
+ duration: DURATION,
49
+ easing: visible
50
+ ? react_native_1.Easing.out(react_native_1.Easing.cubic)
51
+ : react_native_1.Easing.in(react_native_1.Easing.cubic),
54
52
  useNativeDriver: true,
55
- });
56
- fadeInstance.current.start(({ finished }) => {
57
- if (finished && fadeInstance.current) {
58
- fadeInstance.current = null;
59
- if (!visible) {
60
- setRealVisible(false);
61
- }
53
+ }).start(({ finished }) => {
54
+ if (finished && !visible) {
55
+ setMounted(false);
62
56
  }
63
57
  });
64
- return () => {
65
- if (fadeInstance.current) {
66
- fadeInstance.current.stop();
67
- fadeInstance.current = null;
68
- }
69
- };
70
- }, [visible]);
71
- const baseStyle = (0, react_1.useMemo)(() => {
72
- const base = {
73
- backgroundColor: '#fff',
74
- ...(height ? { height } : { minHeight }),
75
- width: position === 'center' ? width ?? 300 : '100%',
76
- };
77
- if (position !== 'center') {
78
- base.position = 'absolute';
79
- base.left = 0;
80
- base.right = 0;
81
- if (position === 'bottom') {
82
- base.bottom = 0;
83
- }
84
- else {
85
- base.top = 0;
86
- }
58
+ }, [visible, progress]);
59
+ if (!mounted)
60
+ return null;
61
+ const baseStyle = {
62
+ backgroundColor: '#fff',
63
+ ...(height ? { height } : { minHeight }),
64
+ width: position === 'center'
65
+ ? (width ?? 300)
66
+ : '100%',
67
+ };
68
+ if (position !== 'center') {
69
+ //上弹出层or下弹出层
70
+ Object.assign(baseStyle, {
71
+ position: 'absolute',
72
+ left: 0,
73
+ right: 0,
74
+ ...(position === 'bottom' ? { bottom: 0 } : { top: 0 }),
75
+ });
76
+ }
77
+ if (round) {
78
+ if (position === 'center') {
79
+ baseStyle.borderRadius = centerRadius;
87
80
  }
88
- if (round) {
89
- if (position === 'center') {
90
- base.borderRadius = centerPopRadius;
91
- }
92
- else if (position === 'bottom') {
93
- base.borderTopLeftRadius = radius;
94
- base.borderTopRightRadius = radius;
95
- }
96
- else {
97
- base.borderBottomLeftRadius = radius;
98
- base.borderBottomRightRadius = radius;
99
- }
81
+ else if (position === 'bottom') {
82
+ baseStyle.borderTopLeftRadius = radius;
83
+ baseStyle.borderTopRightRadius = radius;
100
84
  }
101
- return base;
102
- }, [position, width, height, minHeight, round, radius, centerPopRadius]);
103
- const animatedStyle = (0, react_1.useMemo)(() => {
104
- if (position === 'center') {
105
- return {
106
- opacity: animatedValue
107
- };
85
+ else {
86
+ baseStyle.borderBottomLeftRadius = radius;
87
+ baseStyle.borderBottomRightRadius = radius;
108
88
  }
109
- const distance = height || minHeight;
110
- return {
89
+ }
90
+ const animatedStyle = position === 'center'
91
+ ? { opacity: progress }
92
+ : {
111
93
  transform: [
112
94
  {
113
- translateY: animatedValue.interpolate({
95
+ translateY: progress.interpolate({
114
96
  inputRange: [0, 1],
115
- outputRange: position === 'bottom' ? [distance, 0] : [-distance, 0],
97
+ outputRange: [
98
+ position === 'bottom'
99
+ ? height ?? minHeight
100
+ : -(height ?? minHeight),
101
+ 0,
102
+ ],
116
103
  }),
117
104
  },
118
105
  ],
119
106
  };
120
- }, [position, animatedValue, height, minHeight]);
121
- const closeIconStyle = (0, react_1.useMemo)(() => ({
122
- width: closeIconWidth,
123
- height: closeIconHeight,
124
- }), [closeIconWidth, closeIconHeight]);
125
- const closeButtonPressableStyle = (0, react_1.useMemo)(() => ({
126
- position: 'absolute',
127
- right: 10,
128
- [position === 'top' ? 'bottom' : 'top']: 10,
129
- zIndex: 999,
130
- }), [position]);
131
- if (!realVisible) {
132
- return null;
133
- }
134
- return (<Overlay_1.OverLay useModal={useModal} visible={realVisible} overlayStyle={overlayStyle} onOverlayPress={closeOnOverlayPress ? onClose : undefined}>
107
+ return (<Overlay_1.OverLay visible={mounted} overlayStyle={overlayStyle} onOverlayPress={closeOnOverlayPress ? onClose : undefined}>
135
108
  <react_native_1.Animated.View style={[baseStyle, animatedStyle, style]}>
136
109
  {children}
137
- {closeable && (<react_native_1.Pressable hitSlop={15} onPress={onClose} style={closeButtonPressableStyle}>
138
- <react_native_1.Image source={require('./assets/icon-close.png')} style={closeIconStyle}/>
110
+
111
+ {closeable && (<react_native_1.Pressable hitSlop={15} onPress={onClose} style={{
112
+ position: 'absolute',
113
+ right: 10,
114
+ [position === 'top' ? 'bottom' : 'top']: 10,
115
+ }}>
116
+ <react_native_1.Image source={require('./assets/icon-close.png')} style={closeIconSize}/>
139
117
  </react_native_1.Pressable>)}
140
118
  </react_native_1.Animated.View>
141
119
  </Overlay_1.OverLay>);
@@ -0,0 +1,14 @@
1
+ import React, { ReactNode } from 'react';
2
+ export interface Tab {
3
+ id: string;
4
+ label: string;
5
+ content?: ReactNode;
6
+ }
7
+ export interface TabViewProps {
8
+ tabs: Tab[];
9
+ defaultTab?: string;
10
+ onTabChange?: (tabId: string) => void;
11
+ renderContent?: (tab: Tab) => ReactNode;
12
+ }
13
+ export declare const TabView: React.FC<TabViewProps>;
14
+ //# sourceMappingURL=TabView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TabView.d.ts","sourceRoot":"","sources":["../../src/components/TabView/TabView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAuB,SAAS,EAAE,MAAM,OAAO,CAAC;AAG9D,MAAM,WAAW,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,SAAS,CAAC;CACzC;AAED,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAoE1C,CAAC"}
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.TabView = void 0;
27
+ const react_1 = __importStar(require("react"));
28
+ const react_native_1 = require("react-native");
29
+ const TabView = ({ tabs, defaultTab, onTabChange, renderContent, }) => {
30
+ const [activeTab, setActiveTab] = (0, react_1.useState)(defaultTab || tabs[0]?.id || '');
31
+ // 当 defaultTab 或 tabs 变化时,更新 activeTab
32
+ (0, react_1.useEffect)(() => {
33
+ if (defaultTab && tabs.some((tab) => tab.id === defaultTab)) {
34
+ setActiveTab(defaultTab);
35
+ }
36
+ else if (tabs.length > 0) {
37
+ setActiveTab((currentTab) => {
38
+ // 如果当前 tab 不在 tabs 中,回退到第一个 tab
39
+ if (!tabs.some((tab) => tab.id === currentTab)) {
40
+ return tabs[0].id;
41
+ }
42
+ return currentTab;
43
+ });
44
+ }
45
+ }, [defaultTab, tabs]);
46
+ const handleTabPress = (tabId) => {
47
+ setActiveTab(tabId);
48
+ onTabChange?.(tabId);
49
+ };
50
+ const activeTabData = tabs.find((tab) => tab.id === activeTab) || tabs[0];
51
+ return (<react_native_1.View style={styles.container}>
52
+ <react_native_1.View style={styles.tabContainer}>
53
+ <react_native_1.ScrollView horizontal showsHorizontalScrollIndicator={false}>
54
+ {tabs.map((tab) => (<react_native_1.Pressable key={tab.id} style={styles.tab} onPress={() => handleTabPress(tab.id)}>
55
+ <react_native_1.Text style={[
56
+ styles.tabText,
57
+ activeTab === tab.id && styles.tabTextActive,
58
+ ]}>
59
+ {tab.label}
60
+ </react_native_1.Text>
61
+ {activeTab === tab.id && <react_native_1.View style={styles.tabIndicator}/>}
62
+ </react_native_1.Pressable>))}
63
+ </react_native_1.ScrollView>
64
+ </react_native_1.View>
65
+
66
+ <react_native_1.View style={styles.contentContainer}>
67
+ {activeTabData
68
+ ? renderContent
69
+ ? renderContent(activeTabData)
70
+ : activeTabData.content || null
71
+ : null}
72
+ </react_native_1.View>
73
+ </react_native_1.View>);
74
+ };
75
+ exports.TabView = TabView;
76
+ exports.TabView.displayName = 'TabView';
77
+ const styles = react_native_1.StyleSheet.create({
78
+ container: {
79
+ flex: 1,
80
+ backgroundColor: '#FFFFFF',
81
+ },
82
+ tabContainer: {
83
+ borderBottomWidth: react_native_1.StyleSheet.hairlineWidth,
84
+ borderBottomColor: '#E5E7EB',
85
+ backgroundColor: '#FFFFFF',
86
+ },
87
+ tab: {
88
+ justifyContent: 'center',
89
+ alignItems: 'center',
90
+ paddingVertical: 12,
91
+ paddingHorizontal: 20,
92
+ position: 'relative',
93
+ minWidth: 70,
94
+ },
95
+ tabText: {
96
+ fontSize: 15,
97
+ color: '#9CA3AF',
98
+ fontWeight: '500',
99
+ textAlign: 'center',
100
+ },
101
+ tabTextActive: {
102
+ color: '#111827',
103
+ fontWeight: '700',
104
+ fontSize: 16,
105
+ transform: [{ scale: 1.1 }],
106
+ },
107
+ tabIndicator: {
108
+ position: 'absolute',
109
+ bottom: 0,
110
+ alignSelf: 'center',
111
+ width: 25,
112
+ height: 3,
113
+ backgroundColor: '#EF4444',
114
+ borderRadius: 2,
115
+ },
116
+ contentContainer: {
117
+ flex: 1,
118
+ padding: 20,
119
+ },
120
+ });
package/dist/index.d.ts CHANGED
@@ -11,6 +11,8 @@ export type { OverLayProps } from './Overlay/Overlay';
11
11
  export { Popup } from './Popup/Popup';
12
12
  export type { PopupProps } from './Popup/Popup';
13
13
  export { Text } from './Text/Text';
14
+ export { TabView } from './TabView/TabView';
15
+ export type { TabViewProps, Tab } from './TabView/TabView';
14
16
  export { ThemeProvider, useTheme } from './ThemeConfig/ThemeConfig';
15
17
  export type { Theme } from './ThemeConfig/ThemeConfig';
16
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/components/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACpE,YAAY,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/components/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,YAAY,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACpE,YAAY,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useTheme = exports.ThemeProvider = exports.Text = exports.Popup = exports.OverLay = exports.Header = exports.Empty = exports.Dialog = exports.Button = void 0;
3
+ exports.useTheme = exports.ThemeProvider = exports.TabView = exports.Text = exports.Popup = exports.OverLay = exports.Header = exports.Empty = exports.Dialog = exports.Button = void 0;
4
4
  var Button_1 = require("./Button/Button");
5
5
  Object.defineProperty(exports, "Button", { enumerable: true, get: function () { return Button_1.Button; } });
6
6
  var Dialog_1 = require("./Dialog/Dialog");
@@ -15,6 +15,8 @@ var Popup_1 = require("./Popup/Popup");
15
15
  Object.defineProperty(exports, "Popup", { enumerable: true, get: function () { return Popup_1.Popup; } });
16
16
  var Text_1 = require("./Text/Text");
17
17
  Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return Text_1.Text; } });
18
+ var TabView_1 = require("./TabView/TabView");
19
+ Object.defineProperty(exports, "TabView", { enumerable: true, get: function () { return TabView_1.TabView; } });
18
20
  var ThemeConfig_1 = require("./ThemeConfig/ThemeConfig");
19
21
  Object.defineProperty(exports, "ThemeProvider", { enumerable: true, get: function () { return ThemeConfig_1.ThemeProvider; } });
20
22
  Object.defineProperty(exports, "useTheme", { enumerable: true, get: function () { return ThemeConfig_1.useTheme; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhenryx/react-native-components",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -27,10 +27,12 @@
27
27
  "devDependencies": {
28
28
  "@types/react": "18.2.0",
29
29
  "@types/react-native": "0.70.0",
30
- "typescript": "5.0.4"
30
+ "typescript": "5.0.4",
31
+ "react-native-safe-area-context": "^4.8.0"
31
32
  },
32
33
  "peerDependencies": {
33
34
  "react": ">=18.1.0",
34
- "react-native": ">=0.70.0"
35
+ "react-native": ">=0.70.0",
36
+ "react-native-safe-area-context": ">=4.0.0"
35
37
  }
36
38
  }