背景
- react-native-orientationを使っていたらiosとandroidで動きが違った
事象
- iosとandroidでlandscapeLeft、landscapeRightの動きが反対
サンプル
ios
android
ソースコード
App.js
import React, { Component } from 'react';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import Orientation from 'react-native-orientation';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<TouchableOpacity onPress={() => Orientation.lockToPortrait() } style={[styles.panel, { backgroundColor: 'skyblue' }]}>
<Text>lockToPortrait</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => Orientation.lockToLandscapeLeft() } style={[styles.panel, { backgroundColor: 'lightblue' }]}>
<Text>lockToLandscapeLeft</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => Orientation.lockToLandscapeRight() } style={[styles.panel, { backgroundColor: 'lightgreen' }]}>
<Text>lockToLandscapeRight</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
panel: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
});
index.ios.js/index.android.js
import React from 'react';
import { AppRegistry } from 'react-native';
import App from './App';
AppRegistry.registerComponent('ReactNativeSample', () => App);
追記
- プルリクを遡ったらios側のLeftとRightを入れ替える怪しげなプルリク発見
- つまりこの動きが意図したものということなのか
- https://github.com/yamill/react-native-orientation/pull/122/files