アプリに react-native-image-picker があります。ImagePicker.launchImageLibrary を呼び出している場合、アプリはギャラリーを開く代わりに閉じています。そして、ImagePicker.showImagePicker を呼び出して、Choose from library.. オプションを呼び出すと、同じ動作が発生します。アプリも閉じます。公式ドキュメントと同じコードを使用し、XCode、接続されたライブラリ、Pod ですべてのインストールを行いましたが、エラーはありませんでした。誰か助けてください。
import React, { useState } from 'react'
import { View, FlatList, StyleSheet } from 'react-native'
import ImagePicker from 'react-native-image-picker'
import { ChannelItem, ModalChannelCard, SearchBar, ScreenHeader } from '../../components'
import { data } from '../../dataDraft'
import { TOPICS_SCREEN } from '../routes'
const styles = StyleSheet.create({
container: {
flex: 1
},
textStyle: {
fontSize: 25,
fontWeight: 'bold'
}
})
const ChannelsScreen = ({ navigation }) => {
const { container, textStyle } = styles
const [isModalVisible, setModalVisible] = useState(false)
const [newChannelImage, setNewChannelImage] = useState({
channelImage: null,
loading: false
})
const [newChannelTitle, setNewChannelTitle] = useState('')
const [userInput, setInput] = useState({
value: '',
isEmpty: true
})
const onChangeTexthandler = value => {
setInput({
value,
isEmpty: false
})
}
const onPressXButtonHandler = () => {
setInput({
value: '',
isEmpty: true
})
}
const hideModalHandler = () => {
setModalVisible(false)
}
const setChannelImageHandler = ({ source }) => {
setNewChannelImage({
channelImage: source,
loading: true
})
}
const rightIconPressHandler = () => {
setModalVisible(true)
}
const chooseChannelImageHandler = () => {
const options = {
title: 'Select Image',
storageOptions: {
skipBackup: true,
path: 'images'
}
}
ImagePicker.showImagePicker(options, response => {
console.log('Response = ', response)
if (response.didCancel) {
console.log('User cancelled image picker')
} else if (response.error) {
console.log('ImagePicker error: ', response.error)
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton)
alert(response.customButton)
} else {
const source = { uri: response.uri }
setChannelImageHandler(source.uri)
}
})
}
const newTitleHandler = value => {
setNewChannelTitle(value)
}
return (
<View style={container}>
<ScreenHeader header="Channels" rightIconName="ios-add" onRightIconPress={rightIconPressHandler} />
<SearchBar
value={userInput.value}
placeholder="Search channel..."
isEmpty={userInput.isEmpty}
onChangeText={onChangeTexthandler}
onPressXButton={onPressXButtonHandler}
/>
<ModalChannelCard
buttonAddChannelPushed={newChannelImage.loading}
channelImage={newChannelImage.channelImage}
chooseChannelImage={chooseChannelImageHandler}
createChannel={hideModalHandler}
hideModal={hideModalHandler}
onChangeTitle={newTitleHandler}
titleValue={newChannelTitle}
visible={isModalVisible}
/>
<View style={{ alignItems: 'center' }}>
<FlatList
data={data}
numColumns={2}
autoCorrect={false}
keyboardShouldPersistTaps="always"
keyboardDismissMode="on-drag"
keyExtractor={item => item.image}
renderItem={({ item }) => (
<ChannelItem
channelItemHeader={item.header}
imageSource={item.image}
onPress={() => navigation.navigate(TOPICS_SCREEN)}
/>
)}
/>
</View>
</View>
)
}
export default ChannelsScreen