0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Navigatorでネイティブ風なモーダルアニメーションが使いたい

0
Last updated at Posted at 2016-11-25

Navigator.SceneConfigs.FloatFromBottom だと、元いたviewの縮小アニメーションがついてくる。
あくまでもiOSネイティブのようなモーダルアニメーションが使いたかったので、SceneConfigを作成してみた。

const floatFromBottomLikeNative = {
  ...Navigator.SceneConfigs.FloatFromBottom,
  defaultTransitionVelocity: 8,
  animationInterpolators: {
    into: buildStyleInterpolator({
      opacity: {
        value: 1.0,
        type: 'constant'
      },
      transformTranslate: {
        from: { x: 0, y: Dimensions.get('window').height, z: 0 },
        to: { x: 0, y: 0, z: 0 },
        min: 0,
        max: 1,
        type: 'linear',
        extrapolate: true,
        round: PixelRatio.get()
      }
    }),
    out: buildStyleInterpolator({
      opacity: {
        value: 1.0,
        type: 'constant'
      }
    })
  }
};

ついでにアニメーション無しのsceneConfigも欲しかったので作成してみた。

const noAnimation = {
  ...Navigator.SceneConfigs.PushFromRight,
  defaultTransitionVelocity: 100,
  gestures: null,
  animationInterpolators: {
    into: buildStyleInterpolator({
      opacity: {
        value: 1.0,
        type: 'constant'
      }
    }),
    out: buildStyleInterpolator({
      opacity: {
        value: 1.0,
        type: 'constant'
      }
    })
  }
};

まとめると

custom-scene-config.js
import { Navigator } from 'react-native';
import Dimensions from 'Dimensions';
import PixelRatio from 'PixelRatio';
import buildStyleInterpolator from 'buildStyleInterpolator';

const noAnimation = {
  ...Navigator.SceneConfigs.PushFromRight,
  defaultTransitionVelocity: 100,
  gestures: null,
  animationInterpolators: {
    into: buildStyleInterpolator({
      opacity: {
        value: 1.0,
        type: 'constant'
      }
    }),
    out: buildStyleInterpolator({
      opacity: {
        value: 1.0,
        type: 'constant'
      }
    })
  }
};

const floatFromBottomLikeNative = {
  ...Navigator.SceneConfigs.FloatFromBottom,
  defaultTransitionVelocity: 8,
  animationInterpolators: {
    into: buildStyleInterpolator({
      opacity: {
        value: 1.0,
        type: 'constant'
      },
      transformTranslate: {
        from: { x: 0, y: Dimensions.get('window').height, z: 0 },
        to: { x: 0, y: 0, z: 0 },
        min: 0,
        max: 1,
        type: 'linear',
        extrapolate: true,
        round: PixelRatio.get()
      },
    }),
    out: buildStyleInterpolator({
      opacity: {
        value: 1.0,
        type: 'constant'
      }
    })
  }
};

export const CustomSceneConfigs = {
  NoAnimation: noAnimation,
  FloatFromBottomLikeNative: floatFromBottomLikeNative
};

後は適当にimportして Navigator.SceneConfigs.FloatFromBottom 等を使っている箇所で CustomSceneConfigs.FloatFromBottomLikeNative を代わりに使えばok。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?