不知道原始大小的情况下,使用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、...
透视教学!wepoker辅助透... 透视教学!wepoker辅助透视(透视)天天福建辅助器(确实真的有辅助安装)-哔哩哔哩1、天天福建辅...
透视安卓版!wepoker破解... 透视安卓版!wepoker破解是真的还是假的(透视)至友互娱情怀辅助插件(切实是有辅助下载)-哔哩哔...
透视透视!hhpoker破解工... 透视透视!hhpoker破解工具(透视)决战加血辅助(切实是真的辅助安装)-哔哩哔哩1)决战加血辅助...
透视智能ai!hhpoker外... 透视智能ai!hhpoker外开挂靠谱吗(透视)传送屋万能辅助器(本来有辅助下载)-哔哩哔哩1、很好...
透视挂!wepoker私人局辅... 透视挂!wepoker私人局辅助器怎么用(透视)闲逸官方辅助软件叫什么名字(一直是真的辅助app)-...
今日!wpk透视辅助靠谱吗(透... 今日!wpk透视辅助靠谱吗(透视)新天道辅助脚本(其实是有辅助神器)-哔哩哔哩1、超多福利:超高返利...
据报道!wepoker辅助器是... 据报道!wepoker辅助器是真的吗(透视)大唐辅助神器(本来真的有辅助插件)-哔哩哔哩1、下载好w...
透视脚本!wepoker安装教... 透视脚本!wepoker安装教程(透视)超级三加一辅助工具(本来是有辅助插件)-哔哩哔哩亲,关键说明...
迎来新发展!hhpoker买挂... 迎来新发展!hhpoker买挂(透视)胡乐辅助脚本可靠吗(切实真的有辅助插件)-哔哩哔哩进入游戏-大...