React-native-pager-view: could it possible that ViewPager do not need to set a style with a specific height?

Created on 1 Apr 2020  路  4Comments  路  Source: callstack/react-native-pager-view

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锛宨t 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,
  },
});
question

Most helpful comment

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

All 4 comments

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

Why you can't :

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

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

Why you can't :

const [height, setHeight] = useState(0)
<ViewPager style={[styles.viewPager, { height: height }]} >
<Child setHeight={setHeight} />
</ViewPager>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

nnajiabraham picture nnajiabraham  路  6Comments

hengkx picture hengkx  路  8Comments

ivan3177 picture ivan3177  路  6Comments

olhapi picture olhapi  路  4Comments

panda0603 picture panda0603  路  5Comments