提问人:user3887519 提问时间:11/17/2023 最后编辑:Chrisuser3887519 更新时间:11/19/2023 访问量:33
无法在模态视图中显示 react-native-pdf Pdf
Not able to show the react-native-pdf Pdf inside a Modal view
问:
我有一个组件,我想在弹出窗口中显示pdf。我正在使用 react-native-pdf。 当我直接使用 Pdf 组件时,我可以看到 pdf 内容,但是当我尝试在 Modal 中使用它时,它不起作用。
import Pdf from 'react-native-pdf';
class ModalImage extends React.Component {
render() {
console.log("Props in modalImage",this.props)
return (
<Modal
animationType="fade"
transparent={false}
visible={this.props.modalVisible}
onRequestClose={() => {
this.props.closeModalVisible(!this.props.modalVisible);
}}
>
<View style={styles.modalContainer}>
<Text style={{ position: "absolute", top: 120, marginLeft: 12, marginRight: 12, fontSize: 16, color: "black", fontFamily: "Roboto-Bold" }}>Note: Please wait while we load the file. This may take some time, especially if it is a large file.</Text>
<ScrollView horizontal={true}>
{
this.props.imageType === "pdf" ?
<Pdf style={{height:'100%', width:'100%', backgroundColor:'blue', zIndex: 99999}} source={{ uri: 'file://' + this.state.androidFilePath }} />
:
<Image
style={{
width: this.state.transForm === 90 || this.state.transForm === 270 ? this.state.height : this.state.width,
height: this.state.transForm === 90 || this.state.transForm === 270 ? this.state.width : this.state.height, marginTop: 100,
transform: [{ rotate: this.state.transForm.toString() + "deg" }]
}}
resizeMode="contain"
source={{ uri: this.props.imageAddress }}
/>
}
</ScrollView>
<View style={styles.close_btn_container}>
<TouchableOpacity
onPress={() => {
if (this.state.originWidth + 500 > this.state.width) {
this.setState({ width: this.state.width + 100 })
}
}}
style={{ marginRight: 20 }}
>
<Image
style={{
width: 30,
height: 30
}}
source={require("../../img/zoomIn.png")}
/>
</TouchableOpacity>
<TouchableOpacity
style={{ marginRight: 20 }}
onPress={() => {
if (this.state.originWidth < this.state.width) {
this.setState({ width: this.state.width - 100 });
}
}}
>
<Image
source={require("./../../img/zoomOut.png")}
style={styles.img_icon}
/>
</TouchableOpacity>
<TouchableOpacity
onPress={() => {
if (this.state.transForm >= 360) {
this.setState({ transForm: 90 });
} else {
this.setState({
transForm: this.state.transForm + 90
});
}
}}
style={{ marginRight: 20 }}
>
<Image
style={{
width: 30,
height: 30
}}
source={require("../../img/transform.png")}
/>
</TouchableOpacity>
<TouchableOpacity
style={{ marginRight: 20 }}
onPress={() => {
if (this.props.isFileDownloaded) {
const http = this.props.imageAddress.startsWith("http");
const https = this.props.imageAddress.startsWith("https");
if (http || https) {
this.props.downloadImage(
this.props.imageAddress,
this.props.imageName
);
} else {
Alert.alert(
"Alert",
`The image url does not start with http / https`
);
}
}
}}
>
<Image
source={require("./../../img/download.png")}
style={styles.img_icon}
/>
</TouchableOpacity>
<TouchableOpacity
onPress={() => {
reduxStore.dispatch({
type: ActionTypes.TOGGLE_PATIENT_PROFILE_VIEW,
data: false,
});
this.props.closeModalVisible(!this.props.modalVisible);
}}
>
<Image
resizeMode="cover"
style={styles.img_icon}
source={require("../../img/error.png")}
/>
</TouchableOpacity>
</View>
</View>
</Modal>
);
}
}
我尝试给 z 索引来检查 pdf 是否在模态后面,但它仍然不起作用。 任何指示或帮助将不胜感激。
答:
0赞
Mohamed El Hammi
11/18/2023
#1
您可以尝试以下实现:
import {Dimensions} from 'react-native';
...
<Pdf
style={{
height: Dimensions.get('window').height,
width: Dimensions.get('window').width,
backgroundColor:'blue'
}}
source={{ uri: 'file://' + this.state.androidFilePath }}
/>
或者,如果您不想全屏查看 PDF,则可以选择通过指定宽度和高度(以像素为单位)来调整其尺寸,而不是使用百分比(相对大小)。
评论
0赞
user3887519
11/20/2023
谢谢,它现在开始来了。多谢
评论