callstack / react-native-pager-view

React Native wrapper for the Android ViewPager and iOS UIPageViewController.
MIT License
2.69k stars 413 forks source link

could it possible that ViewPager do not need to set a style with a specific height? #154

Open KingAmo opened 4 years ago

KingAmo commented 4 years ago

Question

the example in readme provide a style={{ flex: 1 }} to ViewPager(like bellow),and it occupy all screen height; but in my case, the pager's height is not specific,it depends; but without a specific height, ViewPager show nothing

so, could the height of ViewPager be flexible ?

import React from 'react';
import {StyleSheet, View, Text} from 'react-native';
import ViewPager from '@react-native-community/viewpager';

const MyPager = () => {
  return (
    <ViewPager style={styles.viewPager} initialPage={0}>
      <View key="1">
        <Text>First page</Text>
      </View>
      <View key="2">
        <Text>Second page</Text>
      </View>
    </ViewPager>
  );
};

const styles = StyleSheet.create({
  viewPager: {
    flex: 1,
  },
});
troZee commented 4 years ago

it depends; but without a specific height, ViewPager show nothing

Why you can't :

<ViewPager style={[styles.viewPager, { height: whatEverHeight }]} />
KingAmo commented 4 years ago

Why you can't :

<ViewPager style={[styles.viewPager, { height: whatEverHeight }]} />

because i want ViewPager just wrap the children, and the children's height is depend on fetched data from api

troZee commented 4 years ago

Why you can't :

const [height, setHeight] = useState(0)
<ViewPager style={[styles.viewPager, { height: height }]} >
<Child setHeight={setHeight} />
</ViewPager>
troZee commented 4 years ago

@KingAmo your issue refers to https://github.com/react-native-community/react-native-viewpager/issues/162