私の問題はかなり簡単です、私はonLongPressイベントの終了を検出しようとしています。基本的に、ユーザーがプレスを解放するとき。長いプレスのネイティブ検出終了に反応する
TouchableWithoutFeedbackでは可能なすべてのイベントを試してみますが、一度に1つのイベントしかトリガーされません。自分の質問に答える
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
機能を確認するコードを共有 – Arunkumar
@arunkumar編集 – Ethrak