I'm trying to create a series of "flashcards" in a ScrollView for a quiz app for my EMT class. A user should tap on a card, and have it flip over to reveal the answer. There are headings between sets of cards within the ScrollView.
The card animation is achieved via this container, which positions the card absolutely. I can not get the card to appear correctly - it either has no height and doesn't appear at all, appears squished, or, if I removed the absolute positioning by editing the FlipView code, the height is doubled to make room for the front and back.
Demo code, which can be pasted directly into index.ios.js:
import React, { Component } from 'react';
import {
AppRegistry,
Text,
View,
ScrollView,
TouchableOpacity
} from 'react-native';
import FlipView from 'react-native-flip-view';
const data = [
{ type: 'default', text: 'some text' },
{ type: 'header', text: 'header text'},
{ type: 'default', text: 'some more text'}
];
class TextLine extends Component {
constructor(props) {
super(props);
this.state = { isFlipped: false };
}
_flip = () => {
this.setState({isFlipped: !this.state.isFlipped});
}
_renderCard = (text) => {
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'red', padding: 10}}>
<TouchableOpacity onPress={this._flip} style={{backgroundColor: 'green', padding: 10}}>
<Text style={{fontSize: 16, padding: 10}}>{text}</Text>
</TouchableOpacity>
</View>
);
}
render() {
if (this.props.type === 'header') {
return <Text style={{fontSize: 20, padding: 20, backgroundColor: 'blue'}}>{this.props.text}</Text>;
}
return (
<FlipView style={{flex: 1}}
front={this._renderCard('Flip')}
back={this._renderCard(this.props.text)}
isFlipped={this.state.isFlipped}
flipAxies="x"
/>
);
}
}
export default class FlipCardTest extends Component {
render() {
return (
<View style={{flex: 1, paddingTop: 20}}>
<ScrollView contentInset={{top: 0, bottom: 100}}>
{data.map((val, idx) => <TextLine key={idx} {...val} />)}
</ScrollView>
</View>
);
}
}
AppRegistry.registerComponent('FlipCardTest', () => FlipCardTest);
Any ideas on how to get the cards to appear correctly? Thanks for any help you can give.