expo - React Native Web中视口上固定位置的元素?
问题描述
我需要将页脚组件粘贴到视口的底部。它上面的内容在一个ScrollView
. 我使用 React Native 和 React Native Web(感谢 Expo)为 web 和 native 构建。
这适用于本机但不适用于网络:
export default function App() {
return (
<View style={styles.container}>
<ScrollView>
{new Array(100).fill("").map((_, index) => {
return <Text key={index}>Blah {index}</Text>;
})}
</ScrollView>
<View style={styles.footer}>
<Text>Im a footer</Text>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
},
footer: {
backgroundColor: "green",
padding: 20,
width: "100%",
},
});
我可以用这段代码破解它。fixed
不受官方支持,但 CSS 已在 Web 中应用。
footer: {
// @ts-ignore
position: Platform.OS === "web" ? "fixed" : undefined,
bottom: 0,
left: 0,
}
没有@ts-ignore
我从 TypeScript 得到这个错误:
类型 '"fixed"' 不能分配给类型 '"absolute" | “亲戚” | 不明确的'。
有没有一种非hacky的方法来做到这一点?
解决方案
推荐阅读
- amcharts - AmCharts 4:显示单个集群的集群和堆叠图表的总数
- javascript - Javascript。从复选框值构建字符串并按 id 过滤
- azure - Azure Kubernetes - 使用环境变量覆盖配置映射值?
- sql - 在 Oracle 中更新联合查询
- c# - 将内容复制到流时出现 HttpRequestException 错误(Cloudinary 上传)
- windows - 从 Windows 中的浏览器打开外部应用程序(来自 mediawiki 页面)
- ios - 如何在 SwiftUI 中更改 ProgressView 口音颜色?
- iis - 托管在本地 IIS 上的 mvc 应用程序被重定向到本地主机
- r - 在返回多个表的函数上应用 rbindlist
- ssl - 挂接服务无法启动 | 搭便车 1.5.2-1 | Ubuntu 20.04.1 LTS