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: [harmony-hybrid]修复导航栏配置无效以及getLaunchOptionsSync无返回值的问题 #15917

Merged
merged 2 commits into from
Jun 18, 2024
Merged
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
18 changes: 15 additions & 3 deletions packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,23 @@ export class NativeApi {
return options
}

// @ts-ignore
@(asyncAndRelease)
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
setNavigationStyle (options: any): void {}

// @ts-ignore
@(asyncAndRelease)
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
setCapsuleState (options: any): void {}

// @ts-ignore
@(syncAndRelease)
setNavigationStyle (options: any): any {
return options
}
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
getCapsuleState (options: any): any {}

// @ts-ignore
@(syncAndRelease)
Expand Down
48 changes: 0 additions & 48 deletions packages/taro-platform-harmony-hybrid/src/api/apis/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import Taro from '@tarojs/api'

import native from './NativeApi'

export * from './ad'
export * from './ai'
export * from './alipay'
Expand All @@ -28,47 +24,3 @@ export * from './swan'
export * from './ui'
export * from './worker'
export * from './wxml'

if (typeof window !== 'undefined') {
// @ts-ignore
window.currentNavigation = {}
}

Taro.eventCenter.on('__taroSetNavigationStyle', (style, textStyle, backgroundColor) => {
if (typeof window !== 'undefined') {
native.setNavigationStyle({ style: style, textStyle: textStyle, backgroundColor: backgroundColor })
// @ts-ignore
Object.assign(window.currentNavigation, {
style,
textStyle,
backgroundColor,
})
// @ts-ignore
if (typeof window.originCapsuleState !== 'undefined') {
// @ts-ignore
window.native?.setCapsuleState?.(window.originCapsuleState)
}
}
})

Taro.eventCenter.on('__taroEnterFullScreen', () => {
native.setNavigationStyle({ style: 'custom', textStyle: 'black', backgroundColor: '#000000' })
// @ts-ignore
if (typeof window.originCapsuleState === 'undefined') {
// @ts-ignore
window.originCapsuleState = window.native?.getCapsuleState().visible
}
// @ts-ignore
window.native?.setCapsuleState?.(false)
})

Taro.eventCenter.on('__taroExitFullScreen', () => {
// @ts-ignore
const { style, textStyle, backgroundColor } = window.currentNavigation
native.setNavigationStyle({ style: style, textStyle: textStyle, backgroundColor: backgroundColor })
// @ts-ignore
if (typeof window.originCapsuleState !== 'undefined') {
// @ts-ignore
window.native?.setCapsuleState?.(window.originCapsuleState)
}
})
9 changes: 9 additions & 0 deletions packages/taro-platform-harmony-hybrid/src/api/apis/taro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import {
getApp,
getCurrentInstance,
getCurrentPages,
initLaunchOptions,
loadNavigationStyle,
navigateBack,
navigateTo,
nextTick,
redirectTo,
registerNavigationStyleHandler,
reLaunch,
switchTab,
} from './index'
Expand All @@ -22,6 +25,12 @@ const requirePlugin = () => {
}
}

loadNavigationStyle()
registerNavigationStyleHandler()

// 同步小程序启动时的参数
Taro.eventCenter.once('__taroRouterLaunch', initLaunchOptions)

const {
Behavior,
getEnv,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
import Taro from '@tarojs/api'
import { addStyle } from '@tarojs/router/dist/style'
import { setTitle } from '@tarojs/router/dist/utils/navigate'

import native from '../../NativeApi'
import { getParameterError, shouldBeObject } from '../../utils'
import { MethodHandler } from '../../utils/handler'

/**
* 导航条与Web层叠布局,导航条可见情况下Web页面顶部空出一定高度的留白
*/
function loadNavigationSytle () {
if (typeof window === 'undefined') {
return
}
// @ts-ignore
const naviHeight = window.navigationHeight ? window.navigationHeight : 0
const css = `
.taro_router .taro_page.taro_navigation_page {
padding-top: ${naviHeight}px;
}

.taro-tabbar__container .taro_page.taro_navigation_page {
max-height: calc(100vh - ${naviHeight}px);
}

.taro-tabbar__container .taro_page.taro_tabbar_page.taro_navigation_page {
max-height: calc(100vh - 50px - ${naviHeight}px);
}`
addStyle(css)
}

loadNavigationSytle()

/**
* 显示页面导航条加载图标
*
Expand Down Expand Up @@ -149,3 +122,4 @@ export const setNavigationBarColor: typeof Taro.setNavigationBarColor = (options
* @null_implementation
*/
export const hideHomeButton = () => Promise.resolve()
export { loadNavigationStyle, registerNavigationStyleHandler } from './style-event'
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import Taro from '@tarojs/api'

import native from '../../NativeApi'

/**
* 导航条与Web层叠布局,导航条可见情况下Web页面顶部空出一定高度的留白
*/
export function loadNavigationStyle () {
if (window === undefined) {
return
}
// @ts-ignore
const naviHeight = window.navigationHeight ? window.navigationHeight : 0
const css = `
.taro_router .taro_page.taro_navigation_page {
padding-top: ${naviHeight}px;
}

.taro-tabbar__container .taro_page.taro_navigation_page {
max-height: calc(100vh - ${naviHeight}px);
}

.taro-tabbar__container .taro_page.taro_tabbar_page.taro_navigation_page {
max-height: calc(100vh - 50px - ${naviHeight}px);
}`
const style = document.createElement('style')
style.innerHTML = css
document.getElementsByTagName('head')[0].appendChild(style)
}

/**
* 监听导航栏设置、进入/退出全屏事件,更改导航栏样式以及显示/隐藏胶囊按钮
*/
export function registerNavigationStyleHandler () {
if (window !== undefined) {
// @ts-ignore
window.currentNavigation = {}
}

Taro.eventCenter.on('__taroSetNavigationStyle', (style, textStyle, backgroundColor) => {
if (window !== undefined) {
native.setNavigationStyle({ style: style, textStyle: textStyle, backgroundColor: backgroundColor })
// @ts-ignore
Object.assign(window.currentNavigation, {
style,
textStyle,
backgroundColor,
})
// @ts-ignore
const { originCapsuleVisible } = window
if (originCapsuleVisible !== undefined) {
native.setCapsuleState({ visible: originCapsuleVisible })
}
}
})

Taro.eventCenter.on('__taroEnterFullScreen', () => {
native.setNavigationStyle({ style: 'custom', textStyle: 'black', backgroundColor: '#000000' })
// @ts-ignore
if (window.originCapsuleVisible === undefined) {
// @ts-ignore
window.originCapsuleVisible = native.getCapsuleState().visible
}
native.setCapsuleState({ visible: false })
})

Taro.eventCenter.on('__taroExitFullScreen', () => {
// @ts-ignore
const { style, textStyle, backgroundColor } = window.currentNavigation
native.setNavigationStyle({ style: style, textStyle: textStyle, backgroundColor: backgroundColor })
// @ts-ignore
const { originCapsuleVisible } = window
if (originCapsuleVisible !== undefined) {
native.setCapsuleState({ visible: originCapsuleVisible })
}
})
}
Loading
Loading