不知道原始大小的情况下,使用React Native Redux对视图的高度进行动画调整。
创始人
2025-01-12 10:30:14
0

要在React Native Redux中对视图的高度进行动画调整,可以按照以下步骤进行:

  1. 安装所需的依赖:

    npm install react-redux redux redux-thunk
    
  2. 创建一个Redux store:

    // store.js
    import { createStore, applyMiddleware } from 'redux';
    import thunk from 'redux-thunk';
    import rootReducer from './reducers';
    
    const store = createStore(rootReducer, applyMiddleware(thunk));
    
    export default store;
    
  3. 创建一个Redux reducer来处理高度调整的操作:

    // reducers.js
    const initialState = {
      height: 0,
    };
    
    const reducer = (state = initialState, action) => {
      switch (action.type) {
        case 'SET_HEIGHT':
          return {
            ...state,
            height: action.payload,
          };
        default:
          return state;
      }
    };
    
    export default reducer;
    
  4. 创建一个Redux action来设置视图的高度:

    // actions.js
    export const setHeight = (height) => ({
      type: 'SET_HEIGHT',
      payload: height,
    });
    
  5. 创建一个React Native组件来调整视图的高度:

    import React, { useEffect } from 'react';
    import { View, Animated, Button } from 'react-native';
    import { useSelector, useDispatch } from 'react-redux';
    import { setHeight } from './actions';
    
    const AnimatedView = () => {
      const height = useSelector((state) => state.height);
      const dispatch = useDispatch();
    
      const animatedHeight = new Animated.Value(height);
    
      useEffect(() => {
        Animated.timing(animatedHeight, {
          toValue: height,
          duration: 500,
          useNativeDriver: false,
        }).start();
      }, [height]);
    
      const handleButtonPress = () => {
        // 在这里设置视图的高度
        const newHeight = 200; // 假设新的高度为200
        dispatch(setHeight(newHeight));
      };
    
      return (
        
          
  6. 使用Redux Provider来包装根组件:

    import React from 'react';
    import { Provider } from 'react-redux';
    import store from './store';
    import AnimatedView from './AnimatedView';
    
    const App = () => {
      return (
        
          
        
      );
    };
    
    export default App;
    

通过上述步骤,你就可以在React Native Redux中对视图的高度进行动画调整了。

相关内容

热门资讯

透视安卓版!wepoker永久... 透视安卓版!wepoker永久免费脚本(透视)德州扑克游戏辅助(原来是有辅助神器)-哔哩哔哩1、用户...
无独有偶!福建大菠萝万能辅助器... 无独有偶!福建大菠萝万能辅助器(透视)丰城双剑必胜辅助(竟然有辅助工具)-哔哩哔哩1、完成福建大菠萝...
透视透视!wepoker智能辅... 透视透视!wepoker智能辅助插件(透视)衢州都莱罗松辅助器(一贯是有辅助神器)-哔哩哔哩1、不需...
透视肯定!wepoker怎么发... 透视肯定!wepoker怎么发冤家牌(透视)芒果辅助器(一直真的是有辅助辅助器)-哔哩哔哩1、进入到...
透视透视!we poker插件... 透视透视!we poker插件(透视)潮友会破解器(好像是有辅助平台)-哔哩哔哩1、点击下载安装,潮...
据相关数据显示!wepoker... 据相关数据显示!wepoker免费钻石(透视)皮皮辅助软件是真的吗(一贯真的有辅助神器)-哔哩哔哩该...
此事备受玩家关注!德州真人透视... 此事备受玩家关注!德州真人透视脚本(透视)山西扣点子的技巧(切实真的是有辅助app)-哔哩哔哩1、在...
透视辅助!wejoker辅助软... 透视辅助!wejoker辅助软件视频(透视)玫瑰大厅辅助(都是存在有辅助修改器)-哔哩哔哩1、下载好...
围绕透视问题!wepoker透... 围绕透视问题!wepoker透视app下载(透视)吉祥填大坑辅助(竟然存在有辅助下载)-哔哩哔哩1、...
透视教程!wepoker透视脚... 透视教程!wepoker透视脚本(透视)wepoker辅助(总是有辅助工具)-哔哩哔哩wepoker...