leecade / leecade/react-native-swiper

Swiper Don't Work in Modal at Android

Open
#435 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
10.5k
Forks
2.3k
PR merge metrics
No merged PRs in 30d

Description

if I press Android HardwareHomeKey let the app back Backstage then open my app, swiper lost sliding effect。
My code:

'use strict';
import React, {
Component
} from 'react';
import {
View,
Text,
Dimensions,
Image,
TouchableOpacity,
Modal,
StyleSheet,
} from 'react-native';
const {
width,
height
} = Dimensions.get('window');
const imageSource = [
require('../images/guide_page1.png'),
require('../images/guide_page2.png'),
require('../images/guide_page3.png'),
require('../images/guide_page4.png'),
];
import { RatiocalWidth, RatiocalHeight, RatiocalFontSize } from '../style';
import { toastShort } from './ToastUtil';
import Swiper from 'react-native-swiper';

export default class WelcomePage extends Component {
constructor(props) {
super(props);
this.state = {
isShowCircleDot: true,
}
this._renderImg = this._renderImg.bind(this);
}

_renderImg() {
    const { _click } = this.props
    let imageSource = [
        require('../images/guide_page1.png'),
        require('../images/guide_page2.png'),
        require('../images/guide_page3.png'),
        require('../images/guide_page4.png'),
    ];
    var imageViews = [];
    for (var i = 0; i < imageSource.length; i++) {
        if (i == imageSource.length - 1) {
            imageViews.push(
                <Image
                    key={i}
                    style={styles.swiperImage}
                    source={imageSource[i]} >
                    <TouchableOpacity style={styles.btnEsperience} onPress={() => _click()} >
                        <Text style={styles.btnText}>
                            马上体验
                        </Text>
                    </TouchableOpacity>
                </Image>
            );
        }
        else {
            imageViews.push(
                <Image
                    key={i}
                    style={styles.swiperImage}
                    source={imageSource[i]}
                    />
            );
        }
    }
    return imageViews
}

_renderImage(val, i) {
    const { _click } = this.props
    return (
        <View key={i} style={{ flex: 1, flexDirection: 'column' }}>
            <Image
                style={styles.swiperImage}
                source={imageSource[i]} >
                {
                    i === imageSource.length - 1 ?
                        <TouchableOpacity style={styles.btnEsperience} onPress={() => _click()} >
                            <Text style={styles.btnText}>
                                马上体验
                        </Text>
                        </TouchableOpacity>
                        :
                        null
                }
            </Image>
        </View>
    );

}

_onMomentumScrollEnd(e, state, context) {
    if (state.index == 3) {
        this.setState({
            isShowCircleDot: false,
        })
    }else {
        this.setState({
            isShowCircleDot: true,
        })
    }
}

render() {
    const { visible } = this.props
    return (
        <Modal
            animationType={'fade'}
            visible={visible}
            transparent
            onRequestClose={(state) => { } } >
            <View style={styles.backgroudView}>
                <Swiper
                    loop={false}
                    autoplay={false}
                    showsButtons={false}
                    showsPagination={false}
                    width={width}
                    height={height}
                    index={0}
                    onMomentumScrollEnd={(e, state, context) => this._onMomentumScrollEnd(e, state, context)}>
                    {
                        imageSource.map((val, i) => this._renderImage(val, i))
                    }
                </Swiper>
            </View>
        </Modal >
    );
}

}
const styles = StyleSheet.create({
backgroudView: {
flexGrow: 1,
backgroundColor: '#ffffff',
},
swiperImage: {
width: width,
height: height,
/**
* contain 根据图片本身的宽高比
* cover,
* stretch
*/
resizeMode: Image.resizeMode.stretch,
justifyContent: 'flex-end',
},
btnEsperience: {
marginBottom: RatiocalHeight(160),
width: width / 2,
height: RatiocalHeight(100),
borderColor: '#1D9FF9',
borderRadius: 7,
borderWidth: 1,
alignSelf: 'center',
alignItems: 'center',
justifyContent: 'center',
},
btnText: {
fontSize: RatiocalFontSize(36),
textAlign: 'center',
color: '#1D9FF9',
},
});

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Android hardware Home-key flow shown in the issue: open the Modal, background the app, return to it, and test the Swiper's sliding behavior. Inspect the supplied WelcomePage example, especially the Modal and Swiper interaction, and compare behavior before and after backgrounding. Done means sliding works again after returning to the app.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react-native
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.