DarkMode的后续问题 (HBuilderX更新)

2020-06-19  本文已影响0人  前端小慵卿
图片.png

根据mode判断修改,两个问题,包含样式的切换、语言的切换

 reason
onShow --------- 监听页面显示。页面每次出现在屏幕上都触发,包括从下级页面点返回露出当前页面

1.进入页面时,修改标题,在onShow中执行需要延迟一个小时时间
2.进入页面,样式修改,在onShow中执行同样有延迟

onShow(){
    // #ifdef APP-PLUS
    var style = plus.navigator.getUiStyle();
    if('dark'==style){
        console.log('dark')
        uni.setNavigationBarColor({
        frontColor: '#000000',
        backgroundColor: '#1f1f1f',
          animation: {
            duration: 400,
            timingFunc: 'easeIn'
          }
        })
        
    }else{  
        uni.setNavigationBarColor({
            frontColor: '#000000',
            backgroundColor: '#EA8C1B',
            animation: {
            duration: 400,
            timingFunc: 'easeIn'
              }
        })
    } 
      // #endif
},

官方指出

onShow、onLoad、onReady
页面A第一次入栈的执行顺序: onLoad >= onShow >= onReady
当进入子页面B使用 uni.navigateBack();返回页面A时,
页面A执行的只有onShow


3.对于在App端动态修改原生导航栏----https://ask.dcloud.net.cn/article/35374,使用的方法有改动
button位置的修改
旧版本的写法

    let currentWebview = page.$getAppWebview();
    let titleObj = currentWebview.getStyle().titleNView;
    if (!titleObj.buttons) {
        return;
    }
    if(prevPage.route=="pages/taber/home"){
        titleObj.buttons[1].text = this.i18n.index.Home;
    }else{
        titleObj.buttons[1].text = '';
    }
    currentWebview.setStyle({
        titleNView: titleObj
    });

//更新后的
  var webView = this.$mp.page.$getAppWebview();  
 // 修改buttons  
// index: 按钮索引, style {WebviewTitleNViewButtonStyles } 
  webView.setTitleNViewButtonStyle(1, {
    text: this.i18n.index.Home,  
  });       
上一篇 下一篇

猜你喜欢

热点阅读