Skip to content
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

Fix: 修复 RN 生命周期执行顺序 #1890

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 19 additions & 14 deletions packages/core/src/platform/patch/getDefaultOptions.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,27 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
instance.route = props.route.name
global.__mpxPagesMap = global.__mpxPagesMap || {}
global.__mpxPagesMap[props.route.key] = [instance, props.navigation]
// App onLaunch 在 Page created 之前执行
if (!global.__mpxAppHotLaunched && global.__mpxAppOnLaunch) {
global.__mpxAppOnLaunch(props.navigation)
}
}

const proxy = instance.__mpxProxy = new MpxProxy(rawOptions, instance)
proxy.created()

if (type === 'page') {
const loadParams = {}
const props = propsRef.current
// 此处拿到的props.route.params内属性的value被进行过了一次decode, 不符合预期,此处额外进行一次encode来与微信对齐
if (isObject(props.route.params)) {
for (const key in props.route.params) {
loadParams[key] = encodeURIComponent(props.route.params[key])
}
}
proxy.callHook(ONLOAD, [loadParams])
}

Object.assign(proxy, {
onStoreChange: null,
stateVersion: Symbol(),
Expand Down Expand Up @@ -384,7 +400,9 @@ const pageStatusMap = global.__mpxPageStatusMap = reactive({})

function usePageStatus (navigation, pageId) {
navigation.pageId = pageId
set(pageStatusMap, pageId, '')
if (!hasOwn(pageStatusMap, pageId)) {
set(pageStatusMap, pageId, '')
}
useEffect(() => {
const focusSubscription = navigation.addListener('focus', () => {
pageStatusMap[pageId] = 'show'
Expand Down Expand Up @@ -502,19 +520,6 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
usePageEffect(proxy, pageId)

useEffect(() => {
if (type === 'page') {
if (!global.__mpxAppHotLaunched && global.__mpxAppOnLaunch) {
global.__mpxAppOnLaunch(props.navigation)
}
const loadParams = {}
// 此处拿到的props.route.params内属性的value被进行过了一次decode, 不符合预期,此处额外进行一次encode来与微信对齐
if (isObject(props.route.params)) {
for (const key in props.route.params) {
loadParams[key] = encodeURIComponent(props.route.params[key])
}
}
proxy.callHook(ONLOAD, [loadParams])
}
proxy.mounted()
return () => {
proxy.unmounted()
Expand Down