diff --git a/examples/mini-program-example/src/pages/api/wxml/index.tsx b/examples/mini-program-example/src/pages/api/wxml/index.tsx index a2bac0117dee..6d0d30ee7e25 100644 --- a/examples/mini-program-example/src/pages/api/wxml/index.tsx +++ b/examples/mini-program-example/src/pages/api/wxml/index.tsx @@ -268,7 +268,7 @@ class IntersectionObserverTest extends React.Component { this.observer = undefined } this.observer = this.createIntersectionObserver(data) - TestConsole.consoleResult.call(this, this.observer, apiIndex) + TestConsole.consoleResult.call(this, "createIntersectionObserver:ok", apiIndex) }, }, { @@ -282,8 +282,8 @@ class IntersectionObserverTest extends React.Component { this.observer.disconnect() } this.observer = this.createIntersectionObserver() - this.observer.relativeTo('.scroll-view', data).observe('.ball', (res) => { - TestConsole.consoleOnCallback.call(this, res, 'IntersectionObserver.observe', apiIndex) + this.observer.relativeTo('#IntersectionObserver', data).observe('.ball', (res) => { + TestConsole.consoleOnCallback.call(this, res, 'IntersectionObserver.relativeTo', apiIndex) this.setState({ appear: res.intersectionRatio > 0, }) @@ -296,13 +296,13 @@ class IntersectionObserverTest extends React.Component { left: 0, }, func: (apiIndex, data) => { - TestConsole.consoleTest('IntersectionObserver.relativeTo') + TestConsole.consoleTest('IntersectionObserver.relativeToViewport') if (this.observer) { this.observer.disconnect() } this.observer = this.createIntersectionObserver() this.observer.relativeToViewport(data).observe('.ball', (res) => { - TestConsole.consoleOnCallback.call(this, res, 'IntersectionObserver.observe', apiIndex) + TestConsole.consoleOnCallback.call(this, res, 'IntersectionObserver.relativeToViewport', apiIndex) this.setState({ appear: res.intersectionRatio > 0, }) @@ -338,7 +338,7 @@ class IntersectionObserverTest extends React.Component { return ( IntersectionObserver测试 - + 先创建IntersectionObserver再滚动 diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts index 9ab12d5b3906..f6a78bbff36f 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts @@ -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) @@ -378,11 +390,11 @@ export class NativeApi { return option } - // @ts-ignore - @(asyncAndNotRelease) - getFileInfo (option: any): any { - return option - } + @(asyncAndRelease) + getFileInformation (_option: any): void {} + + @(asyncAndRelease) + getFileInfo (_option: any): void {} // @ts-ignore @(asyncAndNotRelease) diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/offMemoryWarning.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/offMemoryWarning.ts index e03304194f0b..8c30bc8f2d87 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/offMemoryWarning.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/offMemoryWarning.ts @@ -7,5 +7,5 @@ import Taro from '@tarojs/taro' * @null_implementation */ export const offMemoryWarning: typeof Taro.offMemoryWarning = (_callback) => { - + // 支持使用,但实现为空实现,不用业务做兼容 } diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/onMemoryWarning.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/onMemoryWarning.ts index 3fe3f5d3dc9d..ffd000df9648 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/onMemoryWarning.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/device/memory/onMemoryWarning.ts @@ -7,5 +7,5 @@ import Taro from '@tarojs/taro' * @null_implementation */ export const onMemoryWarning: typeof Taro.onMemoryWarning = (_callback) => { - + // 支持使用,但实现为空实现,不用业务做兼容 } diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/index.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/index.ts index bbeafa50fc8c..2c46904c6a73 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/index.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/index.ts @@ -1,7 +1,3 @@ -import Taro from '@tarojs/api' - -import native from './NativeApi' - export * from './ad' export * from './ai' export * from './alipay' @@ -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) - } -}) diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/interface/NativeFileSystemManager.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/interface/NativeFileSystemManager.ts index 7872b2c72d54..7b6c52240ab3 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/interface/NativeFileSystemManager.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/interface/NativeFileSystemManager.ts @@ -22,7 +22,7 @@ export class NativeFileSystemManager implements Taro.FileSystemManager { } getFileInfo (option: any): any { - native.getFileInfo(option) + native.getFileInformation(option) } readFile (option: any): any { diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/media/image/NativeImage.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/media/image/NativeImage.ts new file mode 100644 index 000000000000..6a14277f7f00 --- /dev/null +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/media/image/NativeImage.ts @@ -0,0 +1,10 @@ +import { asyncAndRelease } from '../../harmony-native/ApiDecorator' + +class NativeImage { + @asyncAndRelease + previewImage (_options: any):void {} +} + +const nativeImage = new NativeImage() + +export default nativeImage \ No newline at end of file diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/media/image/previewImage.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/media/image/previewImage.ts index 12d2d7754354..bd464f8c9b3f 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/media/image/previewImage.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/media/image/previewImage.ts @@ -1,17 +1,8 @@ -import { SwiperProps } from '@tarojs/components' -import { - defineCustomElementTaroSwiperCore, - defineCustomElementTaroSwiperItemCore, -} from '@tarojs/components/dist/components' -import { eventCenter } from '@tarojs/runtime' -import { isFunction } from '@tarojs/shared' import Taro from '@tarojs/taro' -import { showActionSheet, showToast } from '@tarojs/taro-h5' -import native from '../../NativeApi' import { shouldBeObject } from '../../utils' import { MethodHandler } from '../../utils/handler' -import { saveImageToPhotosAlbum } from './saveImageToPhotosAlbum' +import nativeImage from './NativeImage' /** * 在新页面中全屏预览图片。预览的过程中用户可以进行保存图片、发送给朋友等操作。 @@ -19,14 +10,7 @@ import { saveImageToPhotosAlbum } from './saveImageToPhotosAlbum' * @canUse previewImage * @__object [urls, current, showmenu] */ -export const previewImage: typeof Taro.previewImage = async (options) => { - // TODO 改为通过 window.__taroAppConfig 获取配置的 Swiper 插件创建节点 - defineCustomElementTaroSwiperCore() - defineCustomElementTaroSwiperItemCore() - const PRESS_TIME = 1000 - const SHOW_TIME = 2000 - const SAVE_IMAGE_BUTTON = 1 - +export const previewImage: typeof Taro.previewImage = (options) => { // options must be an Object const isObject = shouldBeObject(options) if (!isObject.flag) { @@ -34,163 +18,20 @@ export const previewImage: typeof Taro.previewImage = async (options) => { console.error(res.errMsg) return Promise.reject(res) } - - const { urls = [], current, success, fail, complete, showmenu } = options + const { urls = [], current, showmenu, success, fail, complete } = options const handle = new MethodHandler({ name: 'previewImage', success, fail, complete }) - const container = document.createElement('div') - const removeHandler = () => { - eventCenter.off('__taroRouterChange', removeHandler) - container.remove() - eventCenter.trigger('__taroExitFullScreen', {}) - } - // 路由改变后应该关闭预览框 - eventCenter.on('__taroRouterChange', removeHandler) - - container.classList.add('preview-image') - container.style.cssText = - 'position:fixed;top:0;left:0;z-index:999;width:100%;height:100%;overflow:hidden;outline:0;background-color:#111;' - container.addEventListener('click', removeHandler) - - const swiper: HTMLElement & Omit = document.createElement('taro-swiper-core') - // @ts-ignore - swiper.full = true - // @ts-ignore - swiper.zoom = true - - let children: Node[] = [] - - function loadImage (url: string, loadFail: typeof fail): Promise { - return new Promise((resolve) => { - const item = document.createElement('taro-swiper-item-core') - item.style.cssText = 'display:flex;align-items:start;justify-content:center;overflow-y:scroll;' - const image = new Image() - image.style.maxWidth = '100%' - image.src = url - const div = document.createElement('div') - div.classList.add('swiper-zoom-container') - div.style.cssText = 'display:flex;align-items:center;justify-content:center;max-width:100%;min-height:100%;' - div.appendChild(image) - div.style.zIndex = '900' - - let pressTimer - function startPress () { - pressTimer = setTimeout(async function () { - if (!showmenu) { - return - } - try { - const { tapIndex } = await showActionSheet({ - itemList: ['转发给朋友', '保存图片', '收藏', '翻译图片中的文字', '提取文字'], - }) - if (tapIndex !== SAVE_IMAGE_BUTTON) { - return - } - native.downloadFile({ - url: url, // 仅为示例,并非真实的资源 - success: function (res: any) { - // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容 - saveImageToPhotosAlbum({ - filePath: res.tempFilePath, - success: function (res: any) { - showToast({ - title: '保存成功', - icon: 'success', - duration: SHOW_TIME, - }) - handle.success(res) - }, - fail: function (err: any) { - handle.fail(err) - }, - }) - }, - fail: function (err: any) { - handle.fail(err) - }, - }) - } catch (e) { - return handle.fail({ - errMsg: e.errMsg?.replace('^.*:fail ', ''), - }) - } - }, PRESS_TIME) // 这里的1000表示长按的时间,以毫秒为单位,您可以根据需要调整 - } - - function cancelPress () { - clearTimeout(pressTimer) - } - - // 添加触摸事件监听器 - div.addEventListener('touchstart', startPress) - div.addEventListener('touchend', cancelPress) - div.addEventListener('touchmove', cancelPress) - - item.appendChild(div) - // Note: 等待图片加载完后返回,会导致轮播被卡住 - resolve(item) - if (isFunction(loadFail)) { - image.addEventListener('error', (err) => { - loadFail({ errMsg: err.message }) - }) - } + return new Promise((resolve, reject) => { + nativeImage.previewImage({ + urls, + current, + showmenu, + success: (res) => { + handle.success(res, { resolve, reject }) + }, + fail: (res) => { + handle.fail(res, { resolve, reject }) + }, }) - } - - try { - children = await Promise.all(urls.map((e) => loadImage(e, fail))) - } catch (error) { - return handle.fail({ - errMsg: error, - }) - } - - for (let i = 0; i < children.length; i++) { - const child = children[i] - swiper.appendChild(child) - } - - // 根据微信小程序文档标准(https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.previewImage.html) - // current是一个字符串 - let currentIndex = 0 - if (current && typeof current === 'string') { - const index = urls.indexOf(current) - currentIndex = index > -1 ? index : 0 - } - - swiper.current = currentIndex - - // 创建一个固定定位的容器 - const indexContainer = document.createElement('div') - indexContainer.style.position = 'fixed' - indexContainer.style.top = '35px' - indexContainer.style.left = '50%' - indexContainer.style.transform = 'translateX(-50%)' - indexContainer.style.zIndex = '999' // 确保显示在最上层 - container.appendChild(indexContainer) - - // 创建一个div用来显示索引 - const indexDisplay = document.createElement('div') - indexContainer.style.position = 'fixed' - indexDisplay.id = 'index-display' - indexDisplay.style.backgroundColor = '#111' // 设置背景颜色为黑色 - indexDisplay.style.color = 'white' // 设置文字颜色为白色 - indexContainer.style.transform = 'translateX(-50%)' - indexContainer.style.zIndex = '999' // 确保显示在最上层 - indexDisplay.style.border = '1px solid #111' - indexContainer.appendChild(indexDisplay) - indexDisplay.innerText = `${currentIndex + 1} / ${urls.length}` - - // 监听滑块index并渲染 - swiper.addEventListener('change', (e) => { - // @ts-ignore - const index = e.detail.current - indexDisplay.innerText = `${index + 1} / ${urls.length}` }) - - container.appendChild(swiper) - document.body.appendChild(container) - eventCenter.trigger('__taroEnterFullScreen', {}) - - return handle.success() } diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/open-api/soter/checkIsSoterEnrolledInDevice.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/open-api/soter/checkIsSoterEnrolledInDevice.ts index 105f79c2f9b2..75c7db2f8776 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/open-api/soter/checkIsSoterEnrolledInDevice.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/open-api/soter/checkIsSoterEnrolledInDevice.ts @@ -42,16 +42,14 @@ export const checkIsSoterEnrolledInDevice: typeof Taro.checkIsSoterEnrolledInDev ) } - return new Promise((resolve, reject) => { - native.checkIsSupportSoterAuthentication({ - checkAuthMode: checkAuthMode, - success: (res: any) => { - handle.success(res, { resolve, reject }) - }, - fail: (err: any) => { - handle.fail(err, { resolve, reject }) - }, - }) + native.checkIsSupportSoterAuthentication({ + checkAuthMode: checkAuthMode, + success: (res: any) => { + handle.success(res, { resolve, reject }) + }, + fail: (err: any) => { + handle.fail(err, { resolve, reject }) + }, }) }) } diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/taro.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/taro.ts index 43437e72fc00..228451dafb61 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/taro.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/taro.ts @@ -5,10 +5,13 @@ import { getApp, getCurrentInstance, getCurrentPages, + initLaunchOptions, + loadNavigationStyle, navigateBack, navigateTo, nextTick, redirectTo, + registerNavigationStyleHandler, reLaunch, switchTab, } from './index' @@ -22,6 +25,12 @@ const requirePlugin = () => { } } +loadNavigationStyle() +registerNavigationStyleHandler() + +// 同步小程序启动时的参数 +Taro.eventCenter.once('__taroRouterLaunch', initLaunchOptions) + const { Behavior, getEnv, diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/ui/navigation-bar/index.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/ui/navigation-bar/index.ts index 73bd5d1beb0c..ec1bc138d0a9 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/ui/navigation-bar/index.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/ui/navigation-bar/index.ts @@ -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() - /** * 显示页面导航条加载图标 * @@ -149,3 +122,4 @@ export const setNavigationBarColor: typeof Taro.setNavigationBarColor = (options * @null_implementation */ export const hideHomeButton = () => Promise.resolve() +export { loadNavigationStyle, registerNavigationStyleHandler } from './style-event' diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/ui/navigation-bar/style-event.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/ui/navigation-bar/style-event.ts new file mode 100644 index 000000000000..3c2c047b65b7 --- /dev/null +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/ui/navigation-bar/style-event.ts @@ -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 }) + } + }) +} diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/wxml/IntersectionObserver.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/wxml/IntersectionObserver.ts index 56d04aea5c18..4bd6a78f2c93 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/wxml/IntersectionObserver.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/wxml/IntersectionObserver.ts @@ -125,7 +125,7 @@ export class TaroHarmonyHybridIntersectionObserver implements Taro.IntersectionO } public relativeToViewport (margins?: Taro.IntersectionObserver.RelativeToViewportMargins | undefined): Taro.IntersectionObserver { - return this.relativeTo('.taro_page', margins) + return this.relativeTo('.taro_router', margins) } private _getCallbackByElement (element: Element) { diff --git a/packages/taro-platform-harmony-hybrid/src/components/components-react/Map/Map.tsx b/packages/taro-platform-harmony-hybrid/src/components/components-react/Map/Map.tsx index 769265b27939..6762ea8bb929 100644 --- a/packages/taro-platform-harmony-hybrid/src/components/components-react/Map/Map.tsx +++ b/packages/taro-platform-harmony-hybrid/src/components/components-react/Map/Map.tsx @@ -51,6 +51,9 @@ class HosMap extends React.Component { constructor (props: IProps) { super(props) this.componentId = `HosMap_${Math.floor(Math.random() * 100000)}_${Date.now()}` + } + + componentDidMount (): void { const { latitude, longitude, @@ -77,6 +80,7 @@ class HosMap extends React.Component { onError, onAnchorPointTap, } = this.props + this.nativeRenderArgs = { componentId: this.componentId, latitude, diff --git a/packages/taro-platform-harmony-hybrid/src/runtime/apis/index.ts b/packages/taro-platform-harmony-hybrid/src/runtime/apis/index.ts index 028aa9146b5c..b6ddbf3a5468 100644 --- a/packages/taro-platform-harmony-hybrid/src/runtime/apis/index.ts +++ b/packages/taro-platform-harmony-hybrid/src/runtime/apis/index.ts @@ -1,9 +1,6 @@ import definition from '@tarojs/plugin-platform-harmony-hybrid/dist/definition.json' import isMatchWith from 'lodash-es/isMatchWith' import setWith from 'lodash-es/setWith' -import { initLaunchOptions } from 'src/api/apis' -import native from 'src/api/apis/NativeApi' -import { invertColor } from 'src/api/apis/utils/colorConvert' import Taro from './taro' @@ -30,173 +27,3 @@ export function canIUse (scheme = '') { } export default Taro - -// 同步小程序启动时的参数 -Taro.eventCenter.once('__taroRouterLaunch', initLaunchOptions) - -if (typeof window !== 'undefined') { - // @ts-ignore - window.currentNavigation = {} -} - - -// 更新导航栏状态 -Taro.eventCenter.on('__taroSetNavigationStyle', (style, textStyle, backgroundColor) => { - if (typeof window !== 'undefined') { - if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { - // 当前处于深色模式,对textStyle和backgroundColor进行反转 - textStyle = textStyle === 'black' ? 'white' : 'black' - backgroundColor = invertColor(backgroundColor) - } - native.setNavigationStyle({ style, textStyle, 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, textStyle, backgroundColor }) - // @ts-ignore - if (typeof window.originCapsuleState !== 'undefined') { - // @ts-ignore - window.native?.setCapsuleState?.(window.originCapsuleState) - } -}) - - -// 根据是否有导航栏设置页面样式 -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); -}` - - const style = document.createElement('style') - style.innerHTML = css - document.getElementsByTagName('head')[0].appendChild(style) -} - -loadNavigationSytle() - - -// 设置位置选择样式 -function loadChooseLocationStyle () { - const css = ` -.taro_choose_location { - display: flex; - position: fixed; - top: 100%; - z-index: 1; - flex-direction: column; - width: 100%; - height: 100%; - background-color: #fff; - transition: ease top 0.3s; -} -.taro_choose_location_bar { - display: flex; - flex: 0 60px; - height: 60px; - background-color: #ededed; - color: #090909; - align-items: center; -} -.taro_choose_location_back { - position: relative; - flex: 0 40px; - margin-left: 10px; - width: 25px; - height: 30px; -} -.taro_choose_location_back::before { - display: block; - position: absolute; - left: 0; - top: 0; - border: solid 15px; - border-color: transparent #090909 transparent transparent; - width: 0; - height: 0; - content: ""; -} -.taro_choose_location_back::after { - display: block; - position: absolute; - left: 3px; - top: 0; - border: solid 15px; - border-color: transparent #ededed transparent transparent; - width: 0; - height: 0; - content: ""; -} -.taro_choose_location_title { - flex: 1; - padding-left: 30px; - line-height: 60px; -} -.taro_choose_location_submit { - margin-right: 25px; - padding: 0; - border: none; - width: 75px; - height: 40px; - background-color: #08bf62; - line-height: 40px; - font-size: 20px; - color: #fff; -} -.taro_choose_location_frame { - flex: 1; -} -` - - const style = document.createElement('style') - style.innerHTML = css - document.getElementsByTagName('head')[0].appendChild(style) -} - -loadChooseLocationStyle()