透视动画抽屉与反应原生?

时间:2017-11-05 07:53:00

标签: react-native react-native-android react-native-ios react-native-drawer

我想创建像下面这样的透视动画 -

react-native-scaling-drawer

我正在使用react-native-scaling-drawer&目前已经完成 -

我的App.js是根文件,如下所示 -

App.js

const AppNavigator = StackNavigator(
  {
    walkthroughStack: {
      screen: WalkthroughStack,
    },
    drawerStack: {
      screen: DrawerStack,
    },
  },
  {
    initialRouteName: 'walkthroughStack',
    headerMode: 'none',
  },
);

export default AppNavigator;

我的Walkthrough.js文件是显示应用程序演练的文件。如下 -

WalkthroughStack.js

const WalkthroughStack = StackNavigator(
  {
    Walkthrough: {
      screen: Walkthrough,
    },
  },
  {
    headerMode: 'none',
    navigationOptions: {
      headerVisible: false,
    },
    initialRouteName: 'Walkthrough',
  },
);

export default WalkthroughStack;

我的DrawerStack.js是包含repo -

中显示的动画的文件

DrawerStack.js

let defaultScalingDrawerConfig = {
  scalingFactor: 0.6,
  minimizeFactor: 0.6,
  swipeOffset: 20
};

class CustomDrawerView extends Component {
  constructor(props) {
    super(props);
  }

  componentWillReceiveProps(nextProps) {
    /** Active Drawer Swipe **/
    if (nextProps.navigation.state.index === 0)
      this._drawer.blockSwipeAbleDrawer(false);

    if (nextProps.navigation.state.index === 0 && this.props.navigation.state.index === 0) {
      this._drawer.blockSwipeAbleDrawer(false);
      this._drawer.close();
    }

    /** Block Drawer Swipe **/
    if (nextProps.navigation.state.index > 0) {
      this._drawer.blockSwipeAbleDrawer(true);
    }
  }

  setDynamicDrawerValue = (type, value) => {
    defaultScalingDrawerConfig[type] = value;
    /** forceUpdate show drawer dynamic scaling example **/
    this.forceUpdate();
  };

  render() {
    const {routes, index} = this.props.navigation.state;
    const ActiveScreen = this.props.router.getComponentForState(this.props.navigation.state);

    return (
      <ScalingDrawer
        ref={ref => this._drawer = ref}
        content={<LeftMenu navigation={this.props.navigation}/>}
        {...defaultScalingDrawerConfig}
        onClose={() => console.log('close')}
        onOpen={() => console.log('open')}
      >
        <ActiveScreen
          navigation={addNavigationHelpers({
            ...this.props.navigation,
            state: routes[index],
            openDrawer: () => this._drawer.open(),
          })}
          dynamicDrawerValue={ (type, val) => this.setDynamicDrawerValue(type, val) }
        />
      </ScalingDrawer>
    )
  }
}

const AppNavigator = StackRouter({
  {
    Main: {
      screen: Main,
    },
    Walkthrough: {
      screen: Walkthrough,
    },
    Typography: {
      screen: Typography,
    },
  },
  {
    headerMode: 'none',
    gesturesEnabled: false,
    navigationOptions: {
      headerVisible: false,
    },
    initialRouteName: 'Main',
  },
);

const CustomDrawer = createNavigationContainer(createNavigator(AppNavigator)(CustomDrawerView));

export default CustomDrawer;

但这并不像repo的README中所示那样工作。怎么做?

1 个答案:

答案 0 :(得分:0)

给出的示例可用于React-Navigation的v1。确保您使用v1进行反应导航