antd mobile(六)react-router 左进右出切换界面
来源:互联网 发布:sql sever设置主键自增 编辑:程序博客网 时间:2024/06/04 06:33
第五节我们配置了页面路由切换,但发现个问题,所有界面都是向左切换的,感觉还是不对啊,仔细分析下原生app,会发现应该是进入是左切换,返回时应该是右切换出。
第一步:修改路由动画配置信息:
修改前的代码:
<ReactCSSTransitionGroup transitionName='left' component="div" transitionEnterTimeout={400} transitionLeaveTimeout={400}> <div key={this.props.location.pathname} style={{position:"absolute", width: "100%"}}> { this.props.children } </div> </ReactCSSTransitionGroup>
将transitionName通过参数来设置
transitionName={animateCls}
而该参数从AppMd里面获取,这里的AppMd是dva封装的models
let {animateCls}=this.props.AppMd.AppMd;
AppMd的文件内容大概如下,初始定义了animateCls,并且定义了相应的reducers来修改animateCls参数。
import {parse} from 'qs'export default { namespace: 'AppMd', state: { pageNavTitle:"钢加ERP系统", animateCls:'right' }, subscriptions: { setup({ dispatch, history }) { // eslint-disable-line }, }, effects: { }, reducers: { setCurAnimate(state, action) { console.log(action.curAnimate); //动态修改当前动画参数 要么是left 要么是right return { ...state, animateCls:action.curAnimate}; } },};
修改后AppPage的代码如下:
import React,{Component} from 'react';import { connect,dispatch } from 'react-redux' // 引入connectimport ReactCSSTransitionGroup from "react-addons-css-transition-group";import style from "./Container.css";class App extends Component { constructor(props, context) { super(props, context); } componentWillMount() { document.body.style.margin = "0px"; // 这是防止页面被拖拽 document.body.addEventListener('touchmove', (ev) => { ev.preventDefault(); }); } render() { let {animateCls}=this.props.AppMd.AppMd; console.log(animateCls) return ( <ReactCSSTransitionGroup transitionName={animateCls} component="div" transitionEnterTimeout={400} transitionLeaveTimeout={400}> <div key={this.props.location.pathname} style={{position:"absolute", width: "100%"}}> { this.props.children } </div> </ReactCSSTransitionGroup> ); }}// 利用connect将组件与Redux绑定起来export default connect((AppMd) => ({AppMd}))(App)
第二步:由于我们要实现左进、右出的动画,所以修改对应的Container.css文件,定义了Left、right 2种动画效果。
:global(.left-enter) { position: absolute; top: 0; background: #fff; z-index: 10000; opacity: 1; transform: translateX(100%);}:global(.left-enter.left-enter-active) { opacity: 1; transform: translateX(0); transition: all 0.4s ease-out;}:global(.left-leave) { opacity: 1; transform: translateX(0);}:global(.left-leave.left-leave-active) { opacity: 1; transform: translateX(-100%); transition: all 0.4s ease-out;}.left { position: relative;} /*right*/:global(.right-enter) { transform: translateX(-100%);}:global(.right-enter.right-enter-active) { transform: translateX(0); transition: all 0.4s ease-out;}:global(.right-leave) { position: absolute; top: 0; background: #fff; z-index: 10000; opacity: 1; transform: translateX(0);}:global(.right-leave.right-leave-active) { opacity: 1; transform: translateX(100%); transition: all 0.4s ease-out;}.left { position: relative;}
第三步:就是在执行界面跳转时,首先调用AppMd/setCurAnimate的dispatch来设置动画参数,再执行跳转。
比如:点击按钮左切换跳转到角色管理界面
dispatch({ type: 'AppMd/setCurAnimate', curAnimate:'left' }); const url=object["url"]; dispatch(routerRedux.push({ pathname: '/Role' }));
点击角色界面的返回按钮实现右出
dispatch({ type: 'AppMd/setCurAnimate', curAnimate:curAnimate }); browserHistory.goBack();
ok这样就实现了左进右出切换界面
阅读全文
0 0
- antd mobile(六)react-router 左进右出切换界面
- antd mobile(五)react-router界面切换动画
- react项目的组件库antd-mobile
- create-react-app + antd-mobile配置
- react+react-router 4.0+redux+antd 购物车实战项目
- 学习react,redux,router,antd的一些感悟(见解)
- React-Router+antd+webpack+babel的一个详细demo
- antd-mobile
- Create-React-App创建antd-mobile开发环境
- antd mobile(四) highcharts集成---采用react-highcharts
- 在react-native中引入antd-mobile遇到的问题
- Create-React-App创建antd-mobile开发环境
- 使用Create-React-App脚手架创建antd-mobile开发环境
- react中安装antd-mobile时出现错误
- react实战--antd、react-router-dom v4 解决菜单和地址同步问题
- React(antd和react-bootstrap)的HelloWorld Demo
- React导航栏效果(antd+react router4.0)
- react+antd---1
- Handler常见发送消息方法
- 孤儿进程与僵尸进程
- HDU 3790 最短路径问题(dijkstra)
- 高效率技术学习方法
- 学生代码笔记-0.2
- antd mobile(六)react-router 左进右出切换界面
- MySql练习题
- go interface 例子
- chrome的拓展程序面板
- Android 开发中需要知道的注解基础
- java图片处理工具类
- javascript数据结构系列(一)-线性表
- Android 与 JS交互之取出 链接
- qt5基础2