Skip to content

Commit

Permalink
fix: 修复导航栏相关API以及补充测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
guoenxuan committed Sep 7, 2023
1 parent 2f80994 commit 10ec291
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 31 deletions.
4 changes: 2 additions & 2 deletions examples/mini-program-example/project.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"miniprogramRoot": "dist/",
"projectname": "mini-program-example",
"description": "小程序demo",
"appid": "wx16ae4838cf116f8f",
"appid": "wx41a918608f3bc705",
"setting": {
"urlCheck": true,
"es6": false,
Expand All @@ -29,4 +29,4 @@
"tabIndent": "insertSpaces",
"tabSize": 2
}
}
}
2 changes: 1 addition & 1 deletion examples/mini-program-example/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="format-detection" content="telephone=no,address=no">
<meta name="apple-mobile-web-app-status-bar-style" content="white">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
<title>mini-program-example</title>
<title></title>
<script><%= htmlWebpackPlugin.options.script %></script>
</head>
<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export default class Index extends React.Component {
TestConsole.consoleTest('setEnableDebug')
Taro.setEnableDebug({
enableDebug: true,
success (res) {
success(res) {
TestConsole.consoleSuccess(res)
},
fail (res) {
fail(res) {
TestConsole.consoleFail(res)
},
complete (res) {
complete(res) {
TestConsole.consoleComplete(res)
},
}).then((res) => {
Expand Down Expand Up @@ -135,7 +135,7 @@ export default class Index extends React.Component {
},
],
}
render () {
render() {
const { list } = this.state
return (
<View className='api-page'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TestConsole } from '@/util/util'
* 基础-更新
* @returns
*/
let UpdateManager;
let UpdateManager
export default class Index extends React.Component {
state = {
list: [
Expand Down Expand Up @@ -61,7 +61,7 @@ export default class Index extends React.Component {
},
],
}
render () {
render() {
const { list } = this.state
return (
<View className='api-page'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class Index extends React.Component {
},
],
}
render () {
render() {
const { list } = this.state
return (
<View className='api-page'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,37 @@ export default class Index extends React.Component {
list: [
{
id: 'showNavigationBarLoading',
func: null,
func: (apiIndex) => {
TestConsole.consoleTest('Taro.showNavigationBarLoading')
Taro.showNavigationBarLoading({
success: (res) => {
TestConsole.consoleSuccess.call(this, res, apiIndex)
},
fail: (res) => {
TestConsole.consoleFail.call(this, res, apiIndex)
},
complete: (res) => {
TestConsole.consoleComplete.call(this, res, apiIndex)
},
})
},
},
{
id: 'hideNavigationBarLoading',
func: (apiIndex) => {
TestConsole.consoleTest('Taro.hideNavigationBarLoading')
Taro.hideNavigationBarLoading({
success: (res) => {
TestConsole.consoleSuccess.call(this, res, apiIndex)
},
fail: (res) => {
TestConsole.consoleFail.call(this, res, apiIndex)
},
complete: (res) => {
TestConsole.consoleComplete.call(this, res, apiIndex)
},
})
},
},
{
id: 'setNavigationBarTitle',
Expand All @@ -40,11 +70,29 @@ export default class Index extends React.Component {
},
{
id: 'setNavigationBarColor',
func: null,
},
{
id: 'hideNavigationBarLoading',
func: null,
inputData: {
frontColor: '#000000',
backgroundColor: '#04305f',
animation: {
duration: 2000,
timingFunc: 'easeIn',
},
},
func: (apiIndex, data) => {
TestConsole.consoleTest('Taro.setNavigationBarColor')
Taro.setNavigationBarColor({
...data,
success: (res) => {
TestConsole.consoleSuccess.call(this, res, apiIndex)
},
fail: (res) => {
TestConsole.consoleFail.call(this, res, apiIndex)
},
complete: (res) => {
TestConsole.consoleComplete.call(this, res, apiIndex)
},
})
},
},
{
id: 'hideHomeButton',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export default class Index extends React.Component {
{
id: 'requirePlugin',
func: () => {
let pluginName = Taro.requirePlugin('test')
TestConsole.consoleNormal('requirePlugin',pluginName)
let pluginName = Taro.requirePlugin('test')
TestConsole.consoleNormal('requirePlugin', pluginName)
},
},
{
Expand All @@ -65,7 +65,7 @@ export default class Index extends React.Component {
},
],
}
render () {
render() {
const { list } = this.state
return (
<View className='api-page'>
Expand Down
83 changes: 71 additions & 12 deletions packages/taro-mpharmony/src/api/ui/navigation-bar/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
import Taro from '@tarojs/api'
import { setTitle } from '@tarojs/router/dist/utils/navigate'

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

// 导航栏
export const showNavigationBarLoading = /* @__PURE__ */ temporarilyNotSupport('showNavigationBarLoading')
/**
* 显示页面导航条加载图标
*/
export const showNavigationBarLoading: typeof Taro.showNavigationBarLoading = (options?) => {
const { success, fail, complete } = (options || {}) as Exclude<typeof options, undefined>
const handle = new MethodHandler({ name: 'showNavigationBarLoading', success, fail, complete })

// @ts-ignore
native.showNavigationBarLoading()
return handle.success()
}

export function setNavigationBarTitle (options?: Taro.setNavigationBarTitle.Option) {
/**
* 隐藏页面导航条加载图标
*/
export const hideNavigationBarLoading: typeof Taro.hideNavigationBarLoading = (options?) => {
const { success, fail, complete } = (options || {}) as Exclude<typeof options, undefined>
const handle = new MethodHandler({ name: 'hideNavigationBarLoading', success, fail, complete })

// @ts-ignore
native.hideNavigationBarLoading()
return handle.success()
}

/**
* 设置页面导航条标题
*/
export const setNavigationBarTitle: typeof Taro.hideNavigationBarLoading = (
options?: Taro.setNavigationBarTitle.Option
) => {
// options must be an Object
const isObject = shouldBeObject(options)
if (!isObject.flag) {
Expand Down Expand Up @@ -38,16 +64,49 @@ export function setNavigationBarTitle (options?: Taro.setNavigationBarTitle.Opti
* 设置页面导航条颜色
*/
export const setNavigationBarColor: typeof Taro.setNavigationBarColor = (options) => {
const { backgroundColor, success, fail, complete } = options
const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete })
const meta = document.createElement('meta')
meta.setAttribute('name', 'theme-color')
meta.setAttribute('content', backgroundColor)
document.head.appendChild(meta)
const apiName = 'setNavigationBarColor'
// options must be an Object
const isObject = shouldBeObject(options)
if (!isObject.flag) {
const res = { errMsg: `${apiName}:fail ${isObject.msg}` }
return Promise.reject(res)
}

const { frontColor, backgroundColor, success, fail, complete, ...otherOptions } = options as Exclude<
typeof options,
undefined
>
const handle = new MethodHandler({ name: apiName, success, fail, complete })

if (!frontColor || typeof frontColor !== 'string') {
return handle.fail({
errMsg: getParameterError({
para: 'frontColor',
correct: 'String',
wrong: frontColor,
}),
})
}

if (frontColor && !['#000000', '#ffffff'].includes(frontColor)) {
return handle.fail({
errMsg: `invalid frontColor "${frontColor}"`,
})
}

if (!backgroundColor || typeof backgroundColor !== 'string') {
return handle.fail({
errMsg: getParameterError({
para: 'backgroundColor',
correct: 'String',
wrong: backgroundColor,
}),
})
}
// @ts-ignore
native.setNavigationBarColor({ frontColor, backgroundColor, ...otherOptions })
return handle.success()
}

export const hideNavigationBarLoading = /* @__PURE__ */ temporarilyNotSupport('hideNavigationBarLoading')

// null-implementation
export const hideHomeButton = () => Promise.resolve()

0 comments on commit 10ec291

Please sign in to comment.