-
Notifications
You must be signed in to change notification settings - Fork 388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat use page wrapper comp #1924
base: master
Are you sure you want to change the base?
Conversation
Blackgan3
commented
Mar 29, 2025
- 抽离公共PageWrapper组件,提供给独立组件输出使用
- global navigationHelper改为运行时注入
import { IntersectionObserverContext, RouteContext, KeyboardAvoidContext } from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/context' | ||
import KeyboardAvoidingView from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/KeyboardAvoidingView' | ||
import { IntersectionObserverContext, RouteContext } from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/context' | ||
import PageWrapper from './pageWrapper' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不用迁移出去,就留在当前模块内作为一个named export就可以
@@ -575,111 +553,16 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) { | |||
} | |||
|
|||
if (type === 'page') { | |||
const { PortalHost, useSafeAreaInsets, GestureHandlerRootView, useHeaderHeight } = global.__navigationHelper | |||
const pageConfig = Object.assign({}, global.__mpxPageConfig, currentInject.pageConfig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
global.__mpxPageConfig的合入放在pageWrapper中
return ({ navigation, route }) => createElement( | ||
PageWrapper, { | ||
pageConfig, | ||
pageStatusMap, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要传递
pageId: currentPageId | ||
}) | ||
|
||
if (navigation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要在hooks前面加条件判断
createElement(PortalHost, | ||
null, | ||
// 组件单独使用时传递children可能为 element 元素 | ||
isValidElement(children) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把pageWrapper设计为一个高阶组件
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context' | ||
import { GestureHandlerRootView } from 'react-native-gesture-handler' | ||
|
||
export { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
放到env/navigationHelper.ios/android.js里去吧
# Conflicts: # packages/core/src/platform/patch/getDefaultOptions.ios.js
# Conflicts: # packages/core/src/platform/patch/getDefaultOptions.ios.js
)) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const pageWrapper = (component)=>{
return (props)=>{
createElement(component, {...props, navigation, route,id})
}
}
const page = (props)=>{
return ...
}
const page2 =pageWrapper(page)
// todo custom portal host for active route | ||
} | ||
return Page | ||
currentInjectPageConfig = currentInject.pageConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不应该走闭包传递,应该走props传递
const currentPageConfig = Object.assign({}, global.__mpxPageConfig, currentInjectPageConfig, pageConfig) | ||
if (!navigation || !route) { | ||
// 独立组件使用时要求传递navigation | ||
error('Using pageWrapper requires passing navigation and route') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
传递error对象,以及可以直接return