Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .agents/skills/mpx2rn/references/rn-script-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ Mpx.config.rnConfig = {
onStateChange(state) {
console.log("navigation state", state)
},
disablePageTransition: true,
openTypeHandler: {
onShareAppMessage(shareInfo) {
console.log("share", shareInfo)
Expand All @@ -718,6 +719,7 @@ Mpx.config.rnConfig = {
| `projectName` | 由构建注入到 RN 入口,与 `AppRegistry.registerComponent` 相关(偏构建侧)。 |
| `parseAppProps` | `(props) => { initialRouteName?, initialParams? }`,解析外层传入 App 根组件的初始路由。 |
| `onStateChange` | 导航 state 变化时回调。 |
| `disablePageTransition` | 为 `true` 时禁用 RN 页面转场动画,框架内部映射为 `animation: "none"`。 |
| `disableAppStateListener` | 为 `true` 时不注册 `AppState` 监听(避免与宿主 App 重复)。 |
| `openTypeHandler` | 对象,注册 `button` 组件在 RN 上 `open-type` 的容器侧实现,未注册对应键时点击会告警。 |
| `openTypeHandler.onShareAppMessage` | 对应模板中 `open-type="share"`:框架会先取当前页 `onShareAppMessage` 的返回(含与默认 `title` / `path` 的合并及可选 `promise` 异步结果),再调用本回调,入参为 `{ title, path, imageUrl? }`,由宿主调起系统分享等能力。 |
Expand Down
14 changes: 14 additions & 0 deletions docs-vitepress/guide/rn/application-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,20 @@ createComponent({

在需要将 RN 应用嵌入到现有的 NA 应用中时,可能需要将 RN 的路由栈同步到 NA 中以便于进行路径关系,此时可在此回调中将 RN 路径栈同步到容器中。

#### mpx.config.rnConfig.disablePageTransition

```ts
boolean
```

用于禁用页面转场动画,默认为 `false`。设置为 `true` 后,框架会在内部导航配置中使用 `animation: 'none'`。

如果需要关闭转场动画,可配置:

```js
mpx.config.rnConfig.disablePageTransition = true
```

#### mpx.config.rnConfig.onAppBack

```ts
Expand Down
14 changes: 14 additions & 0 deletions packages/core/@types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ export interface RnConfig {
*/
onStateChange?: (state: Record<string, any>) => void

/**
* 是否禁用页面转场动画。
*
* @default false
*/
disablePageTransition?: boolean

/**
* 用于获取初始路由配置的函数。
*
Expand All @@ -320,6 +327,13 @@ export interface RnConfig {
*/
disableAppStateListener?: boolean

/**
* RN 导航状态栏是否默认透明。
*
* @default true
*/
statusBarTranslucent?: boolean

/**
* RN 文本类组件是否允许跟随系统字体缩放。
*
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ Mpx.config = {
* react-native 相关配置,用于挂载事件等,如 onShareAppMessage
*/
rnConfig: {
defaultBoxSizing: 'content-box'
defaultBoxSizing: 'content-box',
disablePageTransition: false
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/platform/createApp.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default function createApp (options) {
cb(options)
})
} else if (value === 'hide' || value === 'exit') {
global.__mpxAppCbs.hide.forEach((cb) => {
global.__mpxAppCbs.hide.forEach((cb) => {
cb({
reason: value === 'exit' ? 0 : 3
})
Expand Down Expand Up @@ -216,6 +216,9 @@ export default function createApp (options) {
statusBarTranslucent: Mpx.config.rnConfig.statusBarTranslucent ?? true,
statusBarBackgroundColor: 'transparent'
}
if (Mpx.config.rnConfig.disablePageTransition) {
navScreenOpts.animation = 'none'
}

return createElement(SafeAreaProvider,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { createImageData as canvasCreateImageData } from './ImageData'
import { useConstructorsRegistry } from './constructorsRegistry'
import Portal from '../mpx-portal'

type WebViewInstance = WebView<any>

const stylesheet = StyleSheet.create({
container: { overflow: 'hidden', flex: 0 },
webview: {
Expand Down Expand Up @@ -266,7 +268,7 @@ const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasPr
canvasComponent = createElement(View, innerProps, createElement(
WebView,
{
ref: (element) => {
ref: (element: WebViewInstance | null) => {
if (canvasRef.current) {
canvasRef.current.webview = element
}
Expand All @@ -291,7 +293,7 @@ const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasPr
}

canvasComponent = createElement(View, innerProps, createElement(WebView, {
ref: (element) => {
ref: (element: WebViewInstance | null) => {
if (canvasRef.current) {
canvasRef.current.webview = element
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface WebViewProps {
binderror?: (event: CommonCallbackEvent) => void
[x: string]: any
}
type WebViewInstance = WebView<any>
type Listener = (type: string, callback: (e: Event) => void) => () => void

interface PayloadData {
Expand Down Expand Up @@ -82,7 +83,7 @@ const styles = StyleSheet.create({
}
})

const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((props, ref): JSX.Element | null => {
const _WebView = forwardRef<HandlerRef<WebViewInstance, WebViewProps>, WebViewProps>((props, ref): JSX.Element | null => {
const { src, bindmessage, bindload, binderror } = props
const mpx = global.__mpx
const errorText: ErrorTextMap = {
Expand All @@ -103,7 +104,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
const { pageId } = useContext(RouteContext) || {}
const [pageLoadErr, setPageLoadErr] = useState<boolean>(false)
const currentPage = useMemo(() => getCurrentPage(pageId), [pageId])
const webViewRef = useRef<WebView>(null)
const webViewRef = useRef<WebViewInstance>(null)
const fristLoaded = useRef<boolean>(false)
const isLoadError = useRef<boolean>(false)
const isNavigateBack = useRef<boolean>(false)
Expand All @@ -128,7 +129,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
isNavigateBack.current = false
})

useNodesRef<WebView, WebViewProps>(props, ref, webViewRef, {
useNodesRef<WebViewInstance, WebViewProps>(props, ref, webViewRef, {
style: defaultWebViewStyle
})

Expand Down
Loading