Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16552

FlexDirection Change Based on Orientation Change in React-Native

$
0
0

My Code:

import React, { PureComponent } from 'react'import { StyleSheet, View } from 'react-native'import {    isPortrait} from './Constants'export default class TwoVideoView extends PureComponent {    render() {        return (<View style={styles.conatiner}><View style={[styles.videoHalfView, {backgroundColor: 'white'}]}></View><View style={[styles.videoHalfView, {backgroundColor: 'gray'}]}></View></View>        )    }}const styles = StyleSheet.create({    conatiner: {        flex: 1,        backgroundColor: 'red',        flexDirection: isPortrait ? ('column') : ('row')    },    videoFullView: {        width: '100%',        height: '100%'    },    videoHalfView: {        width: isPortrait ? ('100%') : ('50%'),        height: isPortrait ? ('50%') : ('100%')    }})

Portrait output:

enter image description here

Landscape Output:enter image description here

Expected Output:enter image description here

Can you please help what should I do to get this done?

I tried adding Dimensions.addListener('change') didn't workedI just want to update My View rendering not the other Api Stuff.

I need to change flexDirection: isPortrait ? ('column') : ('row')

export const isPortrait = () => {    const dim = Dimensions.get('screen');    return dim.height >= dim.width;  };

Viewing all articles
Browse latest Browse all 16552

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>