Mon problème est assez simple, j'essaie de détecter la fin d'un événement onLongPress. Fondamentalement, lorsque l'utilisateur relâche la presse. Je vais essayer tous les événements possibles dans TouchableWithoutFeedback mais il n'y a qu'un seul événement qui est déclenché à la fois.React native détecter la fin de la presse longue
import React from 'react'
import {
\t View,
\t Text,
\t Dimensions,
\t CameraRoll
} from 'react-native'
import Camera from 'react-native-camera';
const { width, height } = Dimensions.get('window')
class ImageBrowser extends React.Component {
\t static navigationOptions = {
\t \t title: 'Unsplash Images',
\t }
\t state = {
\t \t images: [],
\t \t loading: true,
\t \t page: 1,
\t \t isRecording : false
\t }
\t takeVideo(){
\t \t this._recordVideo.bind(this);
\t }
\t _recordVideo(){
\t \t this.camera.capture({mode: Camera.constants.CaptureMode.video})
\t \t \t .then((data) => {
\t \t \t \t console.log(data);
\t \t \t })
\t \t \t .catch((err) => {
\t \t \t \t console.log(err)
\t \t \t })
\t }
\t _stopRecord(){
\t \t this.camera.stopCapture();
\t }
\t render() {
\t \t return (
\t \t \t <View style={{flex: 1}}>
\t \t \t \t <Camera
\t \t \t \t \t ref={(cam) => {this.camera = cam;}}
\t \t \t \t \t style={styles.preview}
\t \t \t \t \t aspect={Camera.constants.Aspect.fill}
\t \t \t \t \t type={Camera.constants.Type.front}
\t \t \t \t >
\t \t \t \t \t <Text style={styles.capture} onLongPress={this.takeVideo.bind(this)} onPress={this._stopRecord.bind(this)} onPressOut={this._stopRecord.bind(this)}>[CAPTURE]</Text>
\t \t \t \t </Camera>
\t \t \t </View>
\t \t)
\t }
}
const styles = {
\t preview: {
\t \t flex: 1,
\t \t justifyContent: 'flex-end',
\t \t alignItems: 'center',
\t \t height: Dimensions.get('window').height,
\t \t width: Dimensions.get('window').width
\t },
\t capture: {
\t \t flex: 0,
\t \t backgroundColor: '#fff',
\t \t borderRadius: 5,
\t \t color: '#000',
\t \t padding: 10,
\t \t margin: 40
\t }
}
export default ImageBrowser
Partagez votre code pour vérifier la fonctionnalité – Arunkumar
@arunkumar édité – Ethrak