react-native-swiper icon indicating copy to clipboard operation
react-native-swiper copied to clipboard

White-screen in Android when wrapping Swiper with a ScrollView

Open jeremyhallden opened this issue 7 years ago • 5 comments

I have a ScrollView around the Swiper component in order to have a "refreshControl". This runs fine on iOS, but not on Android.

This is reproduced in this snack https://snack.expo.io/Sy2nReYMN (toggle OS in the bottom right corner)

Expo SDK 32 react-native-swiper 1.5.14

jeremyhallden avatar Jan 13 '19 19:01 jeremyhallden

Had the exact same issue. For some reason this doesn't support an auto height if in a scroll view.

Have to set a hard height value in the style props for the

Shpadoinkle avatar Jan 14 '19 04:01 Shpadoinkle

Had the exact same issue. For some reason this doesn't support an auto height if in a scroll view.

Have to set a hard height value in the style props for the

Setting an explicit height (not %, not flex) on the Swiper component seems to make the content visible.

The height can be set to Dimensions.get("window").height for example, but this is not really desirable since an existing header's height then needs to be subtracted.

jeremyhallden avatar Jan 14 '19 12:01 jeremyhallden

modified your code and got it to work by setting the height dynamically, this works but not if the content exceeds the screen, I'm having a separate issue trying to measure the height of the swiper children wrapped inside a scrollview.


import React, { Component } from 'react';
import { Alert, RefreshControl, SafeAreaView, ScrollView, StyleSheet, Text, View } from 'react-native';
import Swiper from 'react-native-swiper';

export default class App extends Component {

  constructor(props){
    super(props);
    this.state = {
      isRefreshing: false,
      screens: ["Hello swiper", "Beautiful", "And simple"],
      height: -1,
      width: -1
    };
    this.measureLayout = this.measureLayout.bind(this);
  }

  measureLayout({ nativeEvent }) {
    const height = nativeEvent.layout.height;
    const width = nativeEvent.layout.width;
    this.setState({ height, width });
    }


  onRefresh = async () => {
    this.setState({isRefreshing: true})
    setTimeout(() => this.setState({isRefreshing: false}), 1500);
  };

  render() {
    return (
        <ScrollView 
        onLayout={this.measureLayout} 
        refreshControl={
            <RefreshControl
              refreshing={this.state.isRefreshing}
              onRefresh={this.onRefresh} />
          }>
          <Swiper height={this.state.height} style={{}} showsButtons={false} loop={false}>
          {this.state.screens.map(screen => (
            <View style={{flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#9DD6EB'}} key={screen}>
              <Text style={{color: '#fff', fontSize: 30, fontWeight: 'bold'}}>{screen}</Text>
            </View>)
          )}
          </Swiper>
        </ScrollView>
      ); 
  }
}

andyr6381 avatar Jan 25 '19 11:01 andyr6381

have you found a solution?

ethanyuwang avatar Feb 19 '20 21:02 ethanyuwang

@ethanyuwang I had the same issue, i fixed it by upgrading react-native-swiper from 1.5.6 to 1.6.0-rc.3

hazeeb avatar Apr 12 '20 16:04 hazeeb