From a21e9207de4b463ad56b8888648be357deba777b Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Sun, 17 Sep 2017 19:06:31 +0000 Subject: [PATCH] feat(screen): add support for landscape orientation (#333) * feat(android): remove screenOrientation param * feat(ios): add support for landscape orientation * feat(parallax-scroll): change parallax header height when rotating --- android/app/src/main/AndroidManifest.xml | 1 - ios/GitPoint/Info.plist | 3 + src/components/parallax-scroll.component.js | 160 +++++++++++++------- 3 files changed, 105 insertions(+), 59 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index b0c2dd50c..041c30f5d 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -27,7 +27,6 @@ android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize" - android:screenOrientation="portrait" android:windowSoftInputMode="adjustResize"> diff --git a/ios/GitPoint/Info.plist b/ios/GitPoint/Info.plist index c6b33726d..43f8b36f2 100644 --- a/ios/GitPoint/Info.plist +++ b/ios/GitPoint/Info.plist @@ -72,6 +72,9 @@ UISupportedInterfaceOrientations UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + UIInterfaceOrientationPortraitUpsideDown UISupportedInterfaceOrientations~ipad diff --git a/src/components/parallax-scroll.component.js b/src/components/parallax-scroll.component.js index 999ba9a78..271663df9 100644 --- a/src/components/parallax-scroll.component.js +++ b/src/components/parallax-scroll.component.js @@ -1,12 +1,10 @@ -import React from 'react'; -import { View, Text, Dimensions, StyleSheet } from 'react-native'; +import React, { Component } from 'react'; +import { View, Text, Dimensions, StyleSheet, Platform } from 'react-native'; import ParallaxScrollView from 'react-native-parallax-scroll-view'; import { Icon } from 'react-native-elements'; import { colors, fonts, normalize } from 'config'; -const window = Dimensions.get('window'); -const PARALLAX_HEADER_HEIGHT = window.height / 2; const STICKY_HEADER_HEIGHT = 62; type Props = { @@ -21,13 +19,16 @@ type Props = { refreshControl?: React.Element<*>, }; +type State = { + parallaxHeaderHeight: number, +}; + const styles = StyleSheet.create({ background: { position: 'absolute', top: 0, width: window.width, backgroundColor: colors.primaryDark, - height: PARALLAX_HEADER_HEIGHT, }, stickySection: { height: STICKY_HEADER_HEIGHT, @@ -53,63 +54,106 @@ const styles = StyleSheet.create({ }, }); -export const ParallaxScroll = ({ - renderContent, - stickyTitle, - navigateBack, - showMenu, - menuIcon, - menuAction, - navigation, - children, - refreshControl, -}: Props) => - - - - } - renderForeground={renderContent} - renderStickyHeader={() => - - - {stickyTitle} - - } - renderFixedHeader={() => - - {navigateBack && - - navigation.goBack()} - underlayColor="transparent" +export class ParallaxScroll extends Component { + props: Props; + + state: State; + + constructor() { + super(); + this.state = { + parallaxHeaderHeight: this.getParallaxHeaderHeight(), + }; + } + + componentDidMount() { + Dimensions.addEventListener('change', this.dimensionsDidChange); + } + + getParallaxHeaderHeight = (window = Dimensions.get('window')) => { + let devider = 2; + + if (window.width > window.height) { + devider = Platform.OS === 'ios' ? 1.2 : 1.4; + } + + return window.height / devider; + }; + + dimensionsDidChange = ({ window }) => { + this.setState({ + parallaxHeaderHeight: this.getParallaxHeaderHeight(window), + }); + }; + + render() { + const { + renderContent, + stickyTitle, + navigateBack, + showMenu, + menuIcon, + menuAction, + navigation, + children, + refreshControl, + } = this.props; + + return ( + + + } + renderForeground={renderContent} + renderStickyHeader={() => + + + {stickyTitle} + + } + renderFixedHeader={() => + + {navigateBack && + + navigation.goBack()} + underlayColor="transparent" + /> + } - {showMenu && - - + {showMenu && + + + } } - } - refreshControl={refreshControl} - > - {children} - ; + refreshControl={refreshControl} + > + {children} + + ); + } +} ParallaxScroll.defaultProps = { navigateBack: false,