我如何把react-native-video
的一个接一个地在一个滚动视图,渲染html使用react-native-render-html
我已经尝试过,但问题是他们得到放置在对方的顶部,如果我试图放置另一个html元素比我看不到它。
This is my attempt
import React from "react";
import { View, ScrollView, StyleSheet } from "react-native";
import Video from "react-native-video";
import RenderHTML, {
HTMLContentModel,
HTMLElementModel,
} from "react-native-render-html";
import { SCREEN_WIDTH } from "../components/lib/constants";
function RenderHtml({ uri }: { uri: string }) {
return (
<>
<RenderHTML
contentWidth={SCREEN_WIDTH}
source={{ html: uri }}
customHTMLElementModels={{
video: HTMLElementModel.fromCustomModel({
tagName: "video",
mixedUAStyles: {
alignSelf: "center",
},
contentModel: HTMLContentModel.block,
}),
}}
renderers={{
video: (obj1: any, obj2: any) => {
let link = obj1["tnode"].domNode.attribs.src;
return (
<>
<Video
source={{ uri: link }}
resizeMode={"contain"}
style={[{ width: SCREEN_WIDTH, height: 300, flex: 1 }]}
controls={true}
paused={true}
/>
</>
);
},
}}
/>
</>
);
}
// test video uri from expo-video example
export default function Test() {
return (
<ScrollView style={styles.container}>
<RenderHtml
uri={
"<video src='https://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4' /><video src='https://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4' />"
}
/>
</ScrollView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "black",
},
videoContainer: {
flex: 1,
height: 300, // Adjust the height as needed to fit your videos
justifyContent: "center",
alignItems: "center",
},
video: {
width: "100%",
height: "100%",
},
});
1条答案
按热度按时间sd2nnvve1#
问题是你没有在视频标签中使用右括号,所以将
<video ... />
更改为<video ...></video
。