react-native - 如何在本机反应中旋转 Fontisto 图标
问题描述
我导入 Fontistoimport { Fontisto } from "@expo/vector-icons";
添加图标<Fontisto style={styles.windDirectionArrow} name='arrow-up' />
以及旋转它的样式
const styles = StyleSheet.create({
windDirectionArrow: {
fontSize: 40,
transform: [{ rotate: "90deg" }],
},
});
但是转换不起作用,有人知道其他解决方案吗?
我正在渲染的视图看起来像这样
return (
<View style={styles.container}>
{error ? (
<View style={styles.centeredContainer}>
<Text style={styles.text}>Unable to load weather data</Text>
<Text style={styles.text}>{error}</Text>
</View>
) : isLoading ? (
<View style={styles.centeredContainer}>
<Text style={styles.text}>Loading Weather Data</Text>
<ActivityIndicator
style={styles.activityIndicator}
size='large'
color='rgb(255,179,25)'
/>
</View>
) : (
<View style={[styles.centeredContainer]}>
<Fontisto style={styles.text} name={icon} />
<Text style={styles.text}>{temperature}˚C</Text>
<Text style={styles.text}>
<Fontisto name='arrow-up' style={styles.windDirectionArrow} />
{windSpeed}mph
</Text>
<Text style={styles.text}>{weatherCondition}</Text>
</View>
)}
</View>
);
如果我将 Icon 元素包裹在其自身中,它会起作用,但我认为这不是一个干净的解决方案
<Text style={styles.text}>
<View>
<Fontisto name='arrow-up' style={styles.windDirectionArrow} />
</View>
{windSpeed}mph
</Text>
解决方案
它非常适合我
// With Rotation
<Fontisto name="arrow-up" style={styles.windDirectionArrow} />
// Without Rotation
<Fontisto name="arrow-up" style={styles.withoutRottion} />
// When icon is wrapped inside a View and that View is rotated
<View style={styles.windDirectionArrow}>
<Fontisto name="arrow-up" style={{ fontSize: 40 }} />
</View>
我的风格:
windDirectionArrow: {
fontSize: 40,
transform: [{ rotate: '90deg' }],
},
withoutRottion: {
fontSize: 40,
},
还有你为什么不使用arrow-right
fromFontisto
对于文本并排
<View style={{ justifyContent: 'center', alignItems: 'center', flexDirection: 'row' }}>
<View style={styles.windDirectionArrow}>
<Fontisto name="arrow-up" style={{ fontSize: 40 }} />
</View>
<Text style={styles.text}>{windSpeed}mph</Text>
</View>
推荐阅读
- php - 通过 PHPMailer 发送带有 CSV 附件的电子邮件
- java - 使用 armeria 或 asynchttpclient 代理大文件
- ejabberd - ejabberd muc_sub 从 ejabberd 服务器内为用户订阅房间
- javascript - 如何在 PHP 中使用 POST 方法获取 style="display:none" 值
- hazelcast-jet - Hazelcast-Jet drainTo 语法问题
- javascript - 如何在启用 CSP 的静态网站上安装 Disqus?
- python - 仅在特定间隔内插值图
- javascript - 将html添加到javascript
- docker - 使用反向代理通过 URL 路径提供不同的资产
- sql - 如何更高效地获取 SQL 结果