3

我想创建如下透视动画 -

反应原生缩放抽屉

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

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

应用程序.js

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

export default AppNavigator;

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

演练Stack.js

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

export default WalkthroughStack;

MyDrawerStack.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 中所示。怎么做 ?

4

1 回答 1

0

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

于 2019-06-28T09:04:18.887 回答