@mpxjs/webpack-plugin 2.10.7 → 2.10.8-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.
Files changed (138) hide show
  1. package/lib/dependencies/RecordPageConfigsMapDependency.js +1 -1
  2. package/lib/dependencies/RequireExternalDependency.js +61 -0
  3. package/lib/file-loader.js +3 -2
  4. package/lib/index.js +55 -9
  5. package/lib/json-compiler/index.js +1 -0
  6. package/lib/parser.js +1 -1
  7. package/lib/platform/json/wx/index.js +43 -25
  8. package/lib/platform/style/wx/index.js +7 -0
  9. package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
  10. package/lib/platform/template/wx/component-config/index.js +9 -1
  11. package/lib/platform/template/wx/component-config/nav-container.js +27 -0
  12. package/lib/platform/template/wx/component-config/page-container.js +19 -0
  13. package/lib/platform/template/wx/component-config/sticky-header.js +23 -0
  14. package/lib/platform/template/wx/component-config/sticky-section.js +23 -0
  15. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  16. package/lib/react/LoadAsyncChunkModule.js +74 -0
  17. package/lib/react/index.js +3 -1
  18. package/lib/react/processJSON.js +74 -13
  19. package/lib/react/processScript.js +6 -6
  20. package/lib/react/script-helper.js +100 -41
  21. package/lib/runtime/components/ali/mpx-nav-container.mpx +3 -0
  22. package/lib/runtime/components/react/context.ts +27 -7
  23. package/lib/runtime/components/react/dist/context.d.ts +78 -0
  24. package/lib/runtime/components/react/dist/context.js +5 -1
  25. package/lib/runtime/components/react/dist/event.config.d.ts +7 -0
  26. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +7 -0
  27. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +12 -0
  28. package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +135 -0
  29. package/lib/runtime/components/react/dist/mpx-button.d.ts +68 -0
  30. package/lib/runtime/components/react/dist/mpx-button.jsx +2 -2
  31. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +23 -0
  32. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +7 -0
  33. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +6 -0
  34. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +20 -0
  35. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +8 -0
  36. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +10 -0
  37. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +2 -0
  38. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +32 -0
  39. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +52 -0
  40. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +20 -0
  41. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +32 -0
  42. package/lib/runtime/components/react/dist/mpx-form.d.ts +27 -0
  43. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +18 -0
  44. package/lib/runtime/components/react/dist/mpx-image.d.ts +21 -0
  45. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +7 -0
  46. package/lib/runtime/components/react/dist/mpx-input.d.ts +49 -0
  47. package/lib/runtime/components/react/dist/mpx-input.jsx +28 -9
  48. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +12 -0
  49. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +42 -46
  50. package/lib/runtime/components/react/dist/mpx-label.d.ts +20 -0
  51. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +20 -0
  52. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +63 -0
  53. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +8 -6
  54. package/lib/runtime/components/react/dist/mpx-nav-container.d.ts +9 -0
  55. package/lib/runtime/components/react/dist/mpx-nav-container.jsx +23 -0
  56. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +9 -0
  57. package/lib/runtime/components/react/dist/mpx-page-container.d.ts +27 -0
  58. package/lib/runtime/components/react/dist/mpx-page-container.jsx +255 -0
  59. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +6 -0
  60. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +7 -0
  61. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +6 -0
  62. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +6 -0
  63. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +6 -0
  64. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +2 -0
  65. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +6 -0
  66. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +6 -0
  67. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +106 -0
  68. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +31 -0
  69. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +8 -0
  70. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +22 -0
  71. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +14 -0
  72. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +16 -0
  73. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +12 -0
  74. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +11 -0
  75. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +22 -0
  76. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +16 -0
  77. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +15 -0
  78. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +29 -0
  79. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +9 -0
  80. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +20 -0
  81. package/lib/runtime/components/react/dist/mpx-radio.d.ts +26 -0
  82. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +1 -0
  83. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +24 -0
  84. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +14 -0
  85. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +54 -0
  86. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +31 -15
  87. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +7 -0
  88. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +7 -0
  89. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +17 -0
  90. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +117 -0
  91. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +15 -0
  92. package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +45 -0
  93. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +18 -0
  94. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +52 -0
  95. package/lib/runtime/components/react/dist/mpx-swiper.jsx +3 -2
  96. package/lib/runtime/components/react/dist/mpx-switch.d.ts +26 -0
  97. package/lib/runtime/components/react/dist/mpx-text.d.ts +21 -0
  98. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +7 -0
  99. package/lib/runtime/components/react/dist/mpx-video.d.ts +101 -0
  100. package/lib/runtime/components/react/dist/mpx-view.d.ts +34 -0
  101. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +22 -0
  102. package/lib/runtime/components/react/dist/nav.d.ts +11 -0
  103. package/lib/runtime/components/react/dist/nav.jsx +141 -0
  104. package/lib/runtime/components/react/dist/parser.d.ts +39 -0
  105. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +32 -0
  106. package/lib/runtime/components/react/dist/useNavShared.d.ts +2 -0
  107. package/lib/runtime/components/react/dist/useNavShared.js +6 -0
  108. package/lib/runtime/components/react/dist/useNodesRef.d.ts +11 -0
  109. package/lib/runtime/components/react/dist/utils.d.ts +121 -0
  110. package/lib/runtime/components/react/mpx-async-suspense.tsx +180 -0
  111. package/lib/runtime/components/react/mpx-button.tsx +3 -2
  112. package/lib/runtime/components/react/mpx-input.tsx +35 -16
  113. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +46 -45
  114. package/lib/runtime/components/react/mpx-movable-view.tsx +8 -4
  115. package/lib/runtime/components/react/mpx-nav-container.tsx +33 -0
  116. package/lib/runtime/components/react/mpx-page-container.tsx +394 -0
  117. package/lib/runtime/components/react/mpx-scroll-view.tsx +84 -59
  118. package/lib/runtime/components/react/mpx-sticky-header.tsx +181 -0
  119. package/lib/runtime/components/react/mpx-sticky-section.tsx +96 -0
  120. package/lib/runtime/components/react/mpx-swiper.tsx +4 -2
  121. package/lib/runtime/components/react/nav.tsx +172 -0
  122. package/lib/runtime/components/react/types/common.d.ts +19 -0
  123. package/lib/runtime/components/react/useNavShared.ts +8 -0
  124. package/lib/runtime/components/web/mpx-nav-container.vue +13 -0
  125. package/lib/runtime/components/web/mpx-scroll-view.vue +18 -4
  126. package/lib/runtime/components/web/mpx-sticky-header.vue +99 -0
  127. package/lib/runtime/components/web/mpx-sticky-section.vue +15 -0
  128. package/lib/runtime/components/wx/mpx-nav-container.mpx +9 -0
  129. package/lib/runtime/optionProcessorReact.d.ts +18 -0
  130. package/lib/runtime/optionProcessorReact.js +30 -0
  131. package/lib/script-setup-compiler/index.js +27 -5
  132. package/lib/template-compiler/bind-this.js +2 -1
  133. package/lib/template-compiler/compiler.js +27 -6
  134. package/lib/utils/dom-tag-config.js +18 -4
  135. package/lib/utils/trans-async-sub-rules.js +19 -0
  136. package/lib/web/script-helper.js +1 -1
  137. package/package.json +4 -4
  138. package/LICENSE +0 -433
@@ -0,0 +1,39 @@
1
+ interface Token {
2
+ type: string;
3
+ value: string | number;
4
+ }
5
+ interface ExpressionNode {
6
+ type: 'NUMBER';
7
+ value: number;
8
+ }
9
+ export declare class ExpressionParser {
10
+ private tokens;
11
+ private formatter;
12
+ private functions;
13
+ private current;
14
+ constructor(input: string, formatter?: (val: string) => number, functions?: {
15
+ [key: string]: (...args: number[]) => number;
16
+ });
17
+ tokenize(input: string): Token[];
18
+ parse(): ExpressionNode;
19
+ private expression;
20
+ private term;
21
+ private factor;
22
+ private parseArguments;
23
+ private applyOperator;
24
+ private applyFunction;
25
+ }
26
+ interface FuncInfo {
27
+ start: number;
28
+ end: number;
29
+ args: string[];
30
+ }
31
+ export declare function parseFunc(str: string, funcName: string): FuncInfo[];
32
+ export declare class ReplaceSource {
33
+ private _source;
34
+ private _replacements;
35
+ constructor(source: string);
36
+ replace(start: number, end: number, content: string): void;
37
+ source(): string;
38
+ }
39
+ export {};
@@ -0,0 +1,32 @@
1
+ import type { MutableRefObject } from 'react';
2
+ import type { NativeSyntheticEvent } from 'react-native';
3
+ import { ExtendedViewStyle } from './types/common';
4
+ import type { _ViewProps } from './mpx-view';
5
+ type AnimatedOption = {
6
+ duration: number;
7
+ delay: number;
8
+ useNativeDriver: boolean;
9
+ timingFunction: 'linear' | 'ease' | 'ease-in' | 'ease-in-out' | 'ease-out';
10
+ transformOrigin: string;
11
+ };
12
+ export type AnimationStepItem = {
13
+ animatedOption: AnimatedOption;
14
+ rules: Map<string, number | string>;
15
+ transform: Map<string, number>;
16
+ };
17
+ export type AnimationProp = {
18
+ id: number;
19
+ actions: AnimationStepItem[];
20
+ };
21
+ export default function useAnimationHooks<T, P>(props: _ViewProps & {
22
+ enableAnimation?: boolean;
23
+ layoutRef: MutableRefObject<any>;
24
+ transitionend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
25
+ }): {
26
+ enableStyleAnimation: boolean;
27
+ animationStyle?: undefined;
28
+ } | {
29
+ enableStyleAnimation: true;
30
+ animationStyle: ExtendedViewStyle;
31
+ };
32
+ export {};
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare function useNavShared(): readonly [import("react").ReactNode, (value: import("react").ReactNode) => void];
@@ -0,0 +1,6 @@
1
+ import { useContext } from 'react';
2
+ import { NavSharedContext } from './context';
3
+ export function useNavShared() {
4
+ const navSharedValue = useContext(NavSharedContext);
5
+ return [navSharedValue.customNav, navSharedValue.setCustomNav];
6
+ }
@@ -0,0 +1,11 @@
1
+ import { RefObject, ForwardedRef } from 'react';
2
+ type Obj = Record<string, any>;
3
+ export type HandlerRef<T, P> = {
4
+ getNodeInstance(): {
5
+ props: RefObject<P>;
6
+ nodeRef: RefObject<T>;
7
+ instance: Obj;
8
+ };
9
+ };
10
+ export default function useNodesRef<T, P>(props: P, ref: ForwardedRef<HandlerRef<T, P>>, nodeRef: RefObject<T>, instance?: Obj): void;
11
+ export {};
@@ -0,0 +1,121 @@
1
+ import { ReactNode, ReactElement, Dispatch, SetStateAction } from 'react';
2
+ import { LayoutChangeEvent, TextStyle, ImageProps } from 'react-native';
3
+ import { FastImageProps } from '@d11/react-native-fast-image';
4
+ import type { AnyFunc } from './types/common';
5
+ export declare const TEXT_STYLE_REGEX: RegExp;
6
+ export declare const PERCENT_REGEX: RegExp;
7
+ export declare const URL_REGEX: RegExp;
8
+ export declare const SVG_REGEXP: RegExp;
9
+ export declare const BACKGROUND_REGEX: RegExp;
10
+ export declare const TEXT_PROPS_REGEX: RegExp;
11
+ export declare const DEFAULT_FONT_SIZE = 16;
12
+ export declare const HIDDEN_STYLE: {
13
+ opacity: number;
14
+ };
15
+ export declare const isIOS: boolean;
16
+ export declare const isAndroid: boolean;
17
+ export declare const isHarmony: boolean;
18
+ export declare function useNavigation(): Record<string, any> | undefined;
19
+ export declare function omit<T, K extends string>(obj: T, fields: K[]): Omit<T, K>;
20
+ /**
21
+ * 用法等同于 useEffect,但是会忽略首次执行,只在依赖更新时执行
22
+ */
23
+ export declare const useUpdateEffect: (effect: any, deps: any) => void;
24
+ export declare const parseUrl: (cssUrl?: string) => string | undefined;
25
+ export declare const getRestProps: (transferProps?: any, originProps?: any, deletePropsKey?: any) => any;
26
+ export declare function isText(ele: ReactNode): ele is ReactElement;
27
+ export declare function every(children: ReactNode, callback: (children: ReactNode) => boolean): boolean;
28
+ type GroupData<T> = Record<string, Partial<T>>;
29
+ export declare function groupBy<T extends Record<string, any>>(obj: T, callback: (key: string, val: T[keyof T]) => string, group?: GroupData<T>): GroupData<T>;
30
+ export declare function splitStyle<T extends Record<string, any>>(styleObj: T): {
31
+ textStyle?: Partial<T>;
32
+ backgroundStyle?: Partial<T>;
33
+ innerStyle?: Partial<T>;
34
+ };
35
+ interface TransformStyleConfig {
36
+ enableVar?: boolean;
37
+ externalVarContext?: Record<string, any>;
38
+ parentFontSize?: number;
39
+ parentWidth?: number;
40
+ parentHeight?: number;
41
+ }
42
+ export declare function useTransformStyle(styleObj: Record<string, any> | undefined, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }: TransformStyleConfig): {
43
+ hasVarDec: boolean;
44
+ varContextRef: import("react").MutableRefObject<{}>;
45
+ setWidth: Dispatch<SetStateAction<number>>;
46
+ setHeight: Dispatch<SetStateAction<number>>;
47
+ normalStyle: Record<string, any>;
48
+ hasSelfPercent: boolean;
49
+ hasPositionFixed: boolean;
50
+ };
51
+ export interface VisitorArg {
52
+ target: Record<string, any>;
53
+ key: string;
54
+ value: any;
55
+ keyPath: Array<string>;
56
+ }
57
+ export declare function traverseStyle(styleObj: Record<string, any>, visitors: Array<(arg: VisitorArg) => void>): void;
58
+ export declare function setStyle(styleObj: Record<string, any>, keyPath: Array<string>, setter: (arg: VisitorArg) => void): void;
59
+ export declare function splitProps<T extends Record<string, any>>(props: T): {
60
+ textProps?: Partial<T>;
61
+ innerProps?: Partial<T>;
62
+ };
63
+ interface LayoutConfig {
64
+ props: Record<string, any>;
65
+ hasSelfPercent: boolean;
66
+ setWidth?: Dispatch<SetStateAction<number>>;
67
+ setHeight?: Dispatch<SetStateAction<number>>;
68
+ onLayout?: (event?: LayoutChangeEvent) => void;
69
+ nodeRef: React.RefObject<any>;
70
+ }
71
+ export declare const useLayout: ({ props, hasSelfPercent, setWidth, setHeight, onLayout, nodeRef }: LayoutConfig) => {
72
+ layoutRef: import("react").MutableRefObject<{}>;
73
+ layoutStyle: {};
74
+ layoutProps: Record<string, any>;
75
+ };
76
+ export interface WrapChildrenConfig {
77
+ hasVarDec: boolean;
78
+ varContext?: Record<string, any>;
79
+ textStyle?: TextStyle;
80
+ textProps?: Record<string, any>;
81
+ }
82
+ export declare function wrapChildren(props: Record<string, any> | undefined, { hasVarDec, varContext, textStyle, textProps }: WrapChildrenConfig): any;
83
+ export declare const debounce: <T extends AnyFunc>(func: T, delay: number) => ((...args: Parameters<T>) => void) & {
84
+ clear: () => void;
85
+ };
86
+ export declare const useDebounceCallback: <T extends AnyFunc>(func: T, delay: number) => ((...args: Parameters<T>) => void) & {
87
+ clear: () => void;
88
+ };
89
+ export declare const useStableCallback: <T extends AnyFunc | null | undefined>(callback: T) => T extends AnyFunc ? T : () => void;
90
+ export declare function usePrevious<T>(value: T): T | undefined;
91
+ export interface GestureHandler {
92
+ nodeRefs?: Array<{
93
+ getNodeInstance: () => {
94
+ nodeRef: unknown;
95
+ };
96
+ }>;
97
+ current?: unknown;
98
+ }
99
+ export declare function flatGesture(gestures?: Array<GestureHandler>): any[];
100
+ export declare const extendObject: {
101
+ <T extends {}, U>(target: T, source: U): T & U;
102
+ <T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
103
+ <T_2 extends {}, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
104
+ (target: object, ...sources: any[]): any;
105
+ };
106
+ export declare function getCurrentPage(pageId: number | null | undefined): any;
107
+ export declare function renderImage(imageProps: ImageProps | FastImageProps, enableFastImage?: boolean): ReactElement<ImageProps | FastImageProps, string | import("react").JSXElementConstructor<any>>;
108
+ export declare function pickStyle(styleObj: Record<string, any> | undefined, pickedKeys: Array<string>, callback?: (key: string, val: number | string) => number | string): Record<string, any>;
109
+ export declare function useHover({ enableHover, hoverStartTime, hoverStayTime, disabled }: {
110
+ enableHover: boolean;
111
+ hoverStartTime: number;
112
+ hoverStayTime: number;
113
+ disabled?: boolean;
114
+ }): {
115
+ isHover: boolean;
116
+ gesture?: undefined;
117
+ } | {
118
+ isHover: boolean;
119
+ gesture: import("react-native-gesture-handler/lib/typescript/handlers/gestures/panGesture").PanGesture;
120
+ };
121
+ export {};
@@ -0,0 +1,180 @@
1
+ import { useState, ComponentType, useEffect, useCallback, useRef, ReactNode, createElement } from 'react'
2
+ import { View, Image, StyleSheet, Text, TouchableOpacity } from 'react-native'
3
+ import FastImage from '@d11/react-native-fast-image'
4
+
5
+ const asyncChunkMap = new Map()
6
+
7
+ const styles = StyleSheet.create({
8
+ container: {
9
+ flex: 1,
10
+ padding: 20,
11
+ backgroundColor: '#fff'
12
+ },
13
+ loadingImage: {
14
+ width: 100,
15
+ height: 100,
16
+ marginTop: 220,
17
+ alignSelf: 'center'
18
+ },
19
+ buttonText: {
20
+ color: '#fff',
21
+ fontSize: 16,
22
+ fontWeight: '500',
23
+ textAlign: 'center'
24
+ },
25
+ errorImage: {
26
+ marginTop: 80,
27
+ width: 220,
28
+ aspectRatio: 1,
29
+ alignSelf: 'center'
30
+ },
31
+ errorText: {
32
+ fontSize: 16,
33
+ textAlign: 'center',
34
+ color: '#333',
35
+ marginBottom: 20
36
+ },
37
+ retryButton: {
38
+ position: 'absolute',
39
+ bottom: 54,
40
+ left: 20,
41
+ right: 20,
42
+ backgroundColor: '#fff',
43
+ paddingVertical: 15,
44
+ borderRadius: 30,
45
+ marginTop: 40,
46
+ borderWidth: 1,
47
+ borderColor: '#FF5F00'
48
+ },
49
+ retryButtonText: {
50
+ color: '#FF5F00',
51
+ fontSize: 16,
52
+ fontWeight: '500',
53
+ textAlign: 'center'
54
+ }
55
+ })
56
+
57
+ interface DefaultFallbackProps {
58
+ onReload: () => void
59
+ }
60
+
61
+ const DefaultFallback = ({ onReload }: DefaultFallbackProps) => {
62
+ return (
63
+ <View style={styles.container}>
64
+ <Image
65
+ source={{
66
+ uri: 'https://dpubstatic.udache.com/static/dpubimg/Vak5mZvezPpKV5ZJI6P9b_drn-fallbak.png'
67
+ }}
68
+ style={styles.errorImage}
69
+ resizeMode="contain"
70
+ />
71
+ <Text style={styles.errorText}>网络出了点问题,请查看网络环境</Text>
72
+ <TouchableOpacity
73
+ style={styles.retryButton}
74
+ onPress={onReload}
75
+ activeOpacity={0.7}
76
+ >
77
+ <Text style={styles.retryButtonText}>点击重试</Text>
78
+ </TouchableOpacity>
79
+ </View>
80
+ )
81
+ }
82
+
83
+ const DefaultLoading = () => {
84
+ return (
85
+ <View style={styles.container}>
86
+ <FastImage
87
+ style={styles.loadingImage}
88
+ source={{
89
+ uri: 'https://dpubstatic.udache.com/static/dpubimg/439jiCVOtNOnEv9F2LaDs_loading.gif'
90
+ }}
91
+ resizeMode={FastImage.resizeMode.contain}
92
+ ></FastImage>
93
+ </View>
94
+ )
95
+ }
96
+
97
+ interface AsyncSuspenseProps {
98
+ type: 'component' | 'page'
99
+ chunkName: string
100
+ moduleId: string
101
+ innerProps: any,
102
+ loading?: ComponentType<unknown>
103
+ fallback?: ComponentType<unknown>
104
+ getChildren: () => Promise<ReactNode>
105
+ }
106
+
107
+ type ComponentStauts = 'pending' | 'error' | 'loaded'
108
+
109
+ const AsyncSuspense: React.FC<AsyncSuspenseProps> = ({
110
+ type,
111
+ innerProps,
112
+ chunkName,
113
+ moduleId,
114
+ loading,
115
+ fallback,
116
+ getChildren
117
+ }) => {
118
+ const [status, setStatus] = useState<ComponentStauts>('pending')
119
+ const chunkLoaded = asyncChunkMap.has(moduleId)
120
+ const loadChunkPromise = useRef<null | Promise<ReactNode>>(null)
121
+
122
+ const reloadPage = useCallback(() => {
123
+ setStatus('pending')
124
+ }, [])
125
+
126
+ useEffect(() => {
127
+ let cancelled = false
128
+ if (!chunkLoaded && status === 'pending') {
129
+ if (loadChunkPromise.current) {
130
+ loadChunkPromise
131
+ .current.then((res: ReactNode) => {
132
+ if (cancelled) return
133
+ asyncChunkMap.set(moduleId, res)
134
+ setStatus('loaded')
135
+ })
136
+ .catch((e) => {
137
+ if (cancelled) return
138
+ if (type === 'component') {
139
+ global.onLazyLoadError({
140
+ type: 'subpackage',
141
+ subpackage: [chunkName],
142
+ errMsg: `loadSubpackage: ${e.type}`
143
+ })
144
+ }
145
+ loadChunkPromise.current = null
146
+ setStatus('error')
147
+ })
148
+ }
149
+ }
150
+
151
+ return () => {
152
+ cancelled = true
153
+ }
154
+ }, [status])
155
+
156
+ if (chunkLoaded) {
157
+ const Comp = asyncChunkMap.get(moduleId)
158
+ return createElement(Comp, innerProps)
159
+ } else if (status === 'error') {
160
+ if (type === 'page') {
161
+ fallback = fallback || DefaultFallback
162
+ return createElement(fallback as ComponentType<DefaultFallbackProps>, { onReload: reloadPage })
163
+ } else {
164
+ return fallback ? createElement(fallback, innerProps) : null
165
+ }
166
+ } else {
167
+ if (!loadChunkPromise.current) {
168
+ loadChunkPromise.current = getChildren()
169
+ }
170
+ if (type === 'page') {
171
+ return createElement(loading || DefaultLoading)
172
+ } else {
173
+ return fallback ? createElement(fallback, innerProps) : null
174
+ }
175
+ }
176
+ }
177
+
178
+ AsyncSuspense.displayName = 'MpxAsyncSuspense'
179
+
180
+ export default AsyncSuspense
@@ -42,7 +42,8 @@ import {
42
42
  TextStyle,
43
43
  Animated,
44
44
  Easing,
45
- NativeSyntheticEvent
45
+ NativeSyntheticEvent,
46
+ useAnimatedValue
46
47
  } from 'react-native'
47
48
  import { warn } from '@mpxjs/utils'
48
49
  import { GestureDetector, PanGesture } from 'react-native-gesture-handler'
@@ -157,7 +158,7 @@ const timer = (data: any, time = 3000) => new Promise((resolve) => {
157
158
  })
158
159
 
159
160
  const Loading = ({ alone = false }: { alone: boolean }): JSX.Element => {
160
- const image = useRef(new Animated.Value(0)).current
161
+ const image = useAnimatedValue(0)
161
162
 
162
163
  const rotate = image.interpolate({
163
164
  inputRange: [0, 1],
@@ -280,8 +280,8 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
280
280
  }
281
281
 
282
282
  const setKeyboardAvoidContext = () => {
283
- if (adjustPosition && keyboardAvoid) {
284
- keyboardAvoid.current = { cursorSpacing, ref: nodeRef }
283
+ if (keyboardAvoid) {
284
+ keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition }
285
285
  }
286
286
  }
287
287
 
@@ -295,20 +295,39 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
295
295
  }
296
296
 
297
297
  const onFocus = (evt: NativeSyntheticEvent<TextInputFocusEventData>) => {
298
- setKeyboardAvoidContext()
299
- bindfocus && bindfocus(
300
- getCustomEvent(
301
- 'focus',
302
- evt,
303
- {
304
- detail: {
305
- value: tmpValue.current || ''
306
- },
307
- layoutRef
308
- },
309
- props
310
- )
311
- )
298
+ if (!keyboardAvoid?.current) {
299
+ setKeyboardAvoidContext()
300
+ }
301
+
302
+ if (bindfocus && keyboardAvoid?.current) {
303
+ const focusAction = () => {
304
+ bindfocus(
305
+ getCustomEvent(
306
+ 'focus',
307
+ evt,
308
+ {
309
+ detail: {
310
+ value: tmpValue.current || '',
311
+ height: keyboardAvoid.current?.keyboardHeight,
312
+ },
313
+ layoutRef
314
+ },
315
+ props
316
+ )
317
+ )
318
+ if (keyboardAvoid.current?.onKeyboardShow) {
319
+ keyboardAvoid.current.onKeyboardShow = undefined
320
+ }
321
+ }
322
+ if (keyboardAvoid.current.keyboardHeight) {
323
+ // iOS: keyboard 获取高度时机 keyboardWillShow 在 input focus 之前,可以立即执行
324
+ focusAction()
325
+ } else {
326
+ // Android,Harmony: keyboard 获取高度时机 keyboardDidShow 在 input focus 之后,需要延迟回调
327
+ evt.persist()
328
+ keyboardAvoid.current.onKeyboardShow = focusAction
329
+ }
330
+ }
312
331
  }
313
332
 
314
333
  const onBlur = (evt: NativeSyntheticEvent<TextInputFocusEventData>) => {
@@ -1,6 +1,6 @@
1
1
  import React, { ReactNode, useContext, useEffect } from 'react'
2
2
  import { DimensionValue, EmitterSubscription, Keyboard, View, ViewStyle, NativeSyntheticEvent, NativeTouchEvent } from 'react-native'
3
- import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing } from 'react-native-reanimated'
3
+ import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing, cancelAnimation } from 'react-native-reanimated'
4
4
  import { KeyboardAvoidContext } from './context'
5
5
  import { isIOS } from './utils'
6
6
 
@@ -13,18 +13,31 @@ type KeyboardAvoidViewProps = {
13
13
  const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: KeyboardAvoidViewProps) => {
14
14
  const duration = isIOS ? 250 : 300
15
15
  const easing = isIOS ? Easing.inOut(Easing.ease) : Easing.out(Easing.quad)
16
+ const isShow = React.useRef(false)
16
17
 
17
18
  const offset = useSharedValue(0)
18
19
  const basic = useSharedValue('auto')
19
20
  const keyboardAvoid = useContext(KeyboardAvoidContext)
20
21
 
21
22
  const animatedStyle = useAnimatedStyle(() => ({
22
- transform: [{ translateY: -offset.value }],
23
+ // translate/position top可能会导致地步渲染区域缺失
24
+ marginTop: -offset.value,
23
25
  flexBasis: basic.value as DimensionValue
24
26
  }))
25
27
 
26
28
  const resetKeyboard = () => {
29
+ if (!isShow.current) {
30
+ return;
31
+ }
32
+
33
+ isShow.current = false
34
+
27
35
  if (keyboardAvoid?.current) {
36
+ const inputRef = keyboardAvoid.current.ref?.current
37
+ if (inputRef && inputRef.isFocused()) {
38
+ // 修复 Android 点击键盘收起按钮时当前 input 没触发失焦的问题
39
+ inputRef.blur()
40
+ }
28
41
  keyboardAvoid.current = null
29
42
  }
30
43
  offset.value = withTiming(0, { duration, easing })
@@ -40,49 +53,44 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
40
53
  useEffect(() => {
41
54
  let subscriptions: EmitterSubscription[] = []
42
55
 
43
- if (isIOS) {
44
- subscriptions = [
45
- Keyboard.addListener('keyboardWillShow', (evt: any) => {
46
- if (!keyboardAvoid?.current) return
47
- const { endCoordinates } = evt
48
- const { ref, cursorSpacing = 0 } = keyboardAvoid.current
49
- setTimeout(() => {
50
- ref?.current?.measure((x: number, y: number, width: number, height: number, pageX: number, pageY: number) => {
51
- const aboveOffset = offset.value + pageY + height - endCoordinates.screenY
52
- const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing
53
- const belowValue = Math.min(endCoordinates.height, aboveOffset + cursorSpacing)
54
- const value = aboveOffset > 0 ? belowValue : aboveValue
55
- offset.value = withTiming(value, { duration, easing }, (finished) => {
56
- if (finished) {
57
- // Set flexBasic after animation to trigger re-layout and reset layout information
58
- basic.value = '99.99%'
59
- }
60
- })
61
- })
62
- })
63
- }),
64
- Keyboard.addListener('keyboardWillHide', resetKeyboard)
65
- ]
66
- } else {
67
- subscriptions = [
68
- Keyboard.addListener('keyboardDidShow', (evt: any) => {
69
- if (!keyboardAvoid?.current) return
70
- const { endCoordinates } = evt
71
- const { ref, cursorSpacing = 0 } = keyboardAvoid.current
56
+ function keybaordAvoding(evt: any) {
57
+ if (!keyboardAvoid?.current || isShow.current) {
58
+ return
59
+ }
60
+
61
+ isShow.current = true
62
+
63
+ const { endCoordinates } = evt
64
+ const { ref, cursorSpacing = 0, adjustPosition, onKeyboardShow } = keyboardAvoid.current
65
+ keyboardAvoid.current.keyboardHeight = endCoordinates.height
66
+ onKeyboardShow?.()
67
+ if (adjustPosition) {
68
+ setTimeout(() => {
72
69
  ref?.current?.measure((x: number, y: number, width: number, height: number, pageX: number, pageY: number) => {
73
- const aboveOffset = pageY + height - endCoordinates.screenY
74
- const belowOffset = endCoordinates.height - aboveOffset
70
+ const aboveOffset = offset.value + pageY + height - endCoordinates.screenY
75
71
  const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing
76
- const belowValue = Math.min(belowOffset, cursorSpacing)
72
+ const belowValue = Math.min(endCoordinates.height, aboveOffset + cursorSpacing)
77
73
  const value = aboveOffset > 0 ? belowValue : aboveValue
78
- offset.value = withTiming(value, { duration, easing }, (finished) => {
74
+ cancelAnimation(offset)
75
+ offset.value = withTiming(value, { duration, easing }, finished => {
79
76
  if (finished) {
80
77
  // Set flexBasic after animation to trigger re-layout and reset layout information
81
78
  basic.value = '99.99%'
82
79
  }
83
80
  })
84
81
  })
85
- }),
82
+ })
83
+ }
84
+ }
85
+
86
+ if (isIOS) {
87
+ subscriptions = [
88
+ Keyboard.addListener('keyboardWillShow', keybaordAvoding),
89
+ Keyboard.addListener('keyboardWillHide', resetKeyboard)
90
+ ]
91
+ } else {
92
+ subscriptions = [
93
+ Keyboard.addListener('keyboardDidShow', keybaordAvoding),
86
94
  Keyboard.addListener('keyboardDidHide', resetKeyboard)
87
95
  ]
88
96
  }
@@ -93,15 +101,8 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
93
101
  }, [keyboardAvoid])
94
102
 
95
103
  return (
96
- <View style={style} onTouchEnd={onTouchEnd}>
97
- <Animated.View
98
- style={[
99
- contentContainerStyle,
100
- animatedStyle
101
- ]}
102
- >
103
- {children}
104
- </Animated.View>
104
+ <View style={style} onTouchEnd={onTouchEnd} onTouchMove={onTouchEnd}>
105
+ <Animated.View style={[contentContainerStyle, animatedStyle]}>{children}</Animated.View>
105
106
  </View>
106
107
  )
107
108
  }
@@ -70,6 +70,7 @@ interface MovableViewProps {
70
70
  'parent-font-size'?: number
71
71
  'parent-width'?: number
72
72
  'parent-height'?: number
73
+ 'disable-event-passthrough'?: boolean
73
74
  }
74
75
 
75
76
  const styles = StyleSheet.create({
@@ -103,6 +104,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
103
104
  'parent-width': parentWidth,
104
105
  'parent-height': parentHeight,
105
106
  direction = 'none',
107
+ 'disable-event-passthrough': disableEventPassthrough = false,
106
108
  'simultaneous-handlers': originSimultaneousHandlers = [],
107
109
  'wait-for': waitFor = [],
108
110
  style = {},
@@ -557,10 +559,12 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
557
559
  })
558
560
  .withRef(movableGestureRef)
559
561
 
560
- if (direction === 'horizontal') {
561
- gesturePan.activeOffsetX([-5, 5]).failOffsetY([-5, 5])
562
- } else if (direction === 'vertical') {
563
- gesturePan.activeOffsetY([-5, 5]).failOffsetX([-5, 5])
562
+ if (!disableEventPassthrough) {
563
+ if (direction === 'horizontal') {
564
+ gesturePan.activeOffsetX([-5, 5]).failOffsetY([-5, 5])
565
+ } else if (direction === 'vertical') {
566
+ gesturePan.activeOffsetY([-5, 5]).failOffsetX([-5, 5])
567
+ }
564
568
  }
565
569
 
566
570
  if (simultaneousHandlers && simultaneousHandlers.length) {