当前位置:   article > 正文

微信小程序实现每个页面的首页返回按钮上下拖动 (taro使用了MovableArea,MovableView实现,微信小程序类似)_taro movablearea

taro movablearea

1.效果如图:

2.customNavBar.styl代码:

  1. .home_area {
  2. position: fixed;
  3. right: 0rpx;
  4. width: 10rpx !important;
  5. height: 80vh !important;
  6. z-index: 998;
  7. }
  8. .home_view {
  9. text-align: center;
  10. line-height: 30rpx;
  11. padding: 10rpx;
  12. width: 110rpx;
  13. height: 36rpx;
  14. margin-left: -110rpx;
  15. background: #19B58E;
  16. border-radius:50rpx 0 0 50rpx;
  17. z-index: 999;
  18. position: absolute;
  19. right: 0rpx;
  20. top: 800rpx;
  21. }
  22. .home_title {
  23. text-align:center;
  24. color: #fff;
  25. padding: 10rpx 5rpx;
  26. font-family:PingFangSC-Medium;
  27. font-weight:500;
  28. }

3.customNavBar.tsx代码:

  1. import Taro, { Component, Config } from '@tarojs/taro'
  2. import './customNavBar.styl'
  3. import { AtNavBar, AtButton, AtIcon } from 'taro-ui'
  4. import { View, Text, MovableArea, MovableView } from '@tarojs/components'
  5. import { set as setGlobalData, get as getGlobalData } from '../../../constants/globalData'
  6. export default class customNavBar extends Component {
  7. /**自定义的组件
  8. * 指定config的类型声明为: Taro.Config
  9. *
  10. * 由于 typescript 对于 object 类型推导只能推出 Key 的基本类型
  11. * 对于像 navigationBarTextStyle: 'black' 这样的推导出的类型是 string
  12. * 提示和声明 navigationBarTextStyle: 'black' | 'white' 类型冲突, 需要显示声明类型
  13. */
  14. /**
  15. * *************重要API*************
  16. * title:标题
  17. * left:是否展示左边图标
  18. * 其余的需要的时候再扩展
  19. * 使用:1、导入组件:import Cnavbar from '../../components/custom-NavBar/customNavBar'
  20. * 2、使用组件: <Cnavbar title='123' left={true}></Cnavbar>
  21. *
  22. */
  23. config: Config = {
  24. component: true,
  25. }
  26. constructor(props) {
  27. super(props);
  28. }
  29. handleClick(){
  30. Taro.navigateBack();
  31. }
  32. goToHome(){
  33. Taro.redirectTo({
  34. url: '/pages/index/index'
  35. });
  36. }
  37. render() {
  38. const navBarType= getGlobalData('navBarType');
  39. const {title,left}=this.props;
  40. const homeHide = this.props.homeHide ? true:false;
  41. return (
  42. <View className='page' >
  43. <AtNavBar
  44. onClickLeftIcon={this.handleClick.bind(this, '返回')}
  45. title={title}
  46. leftIconType="{{left?'chevron-left':''}}"
  47. fixed={true}
  48. className="{{navBarType?'navBarX':'navBar'}}"
  49. />
  50. {homeHide
  51. ? ""
  52. : <MovableArea className="home_area">
  53. <MovableView className="home_view" onClick={this.goToHome} direction='vertical'>
  54. <AtIcon value='home' size='20' color='#fff'></AtIcon><Text className="home_title">首页</Text>
  55. </MovableView>
  56. </MovableArea>
  57. }
  58. </View>
  59. )
  60. }
  61. }

4.其他页面引用:

  1. import Cnavbar from '../components/custom-NavBar/customNavBar'
  2. ......
  3. <View>
  4. <Cnavbar title='标题' left={false} homeHide={false}></Cnavbar>
  5. </View>

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/1019949
推荐阅读
相关标签
  

闽ICP备14008679号