react-native - React Native 如何在启动画面设置 Gif 图像?
问题描述
我创建了新的反应原生移动应用程序,我需要将 gif 图像设置为启动画面。任何示例或源代码都可以帮助我做到这一点。
render() {
return (
<View style={styles.container}>
{/*<BackgroundImage source={Images.splashScreen}*/}
{/* style = {{width: 315, height: 383}} />*/}
<Image
style={{width: 300, height: 200}}
source={{uri: 'http://gifsstore.com/public/upload/gifs/15609427721560942769.gif'}} />
</View>
);
}
解决方案
这里的这些答案似乎有点误导。该问题询问如何使用本机反应将其添加到启动画面。解决方案说明了如何将 gif 添加到项目中,但没有说明如何将它们添加到启动画面。
启动画面意味着在 JS 包加载之前加载 IErender
来自 react native 的方法在 JS 包加载之前将无法访问。
解决方案:安卓
实际上可以直接在启动画面中有一个gif
将此 repo 视为将 gif 集成到启动画面中的示例。 https://github.com/koral--/android-gif-drawable
我今晚(2020 年 4 月 12 日)用react native 0.62让它工作了
脚步:。
- 按照 react-native-splash-screen 教程创建
/layout/launch_screen/xml
- 添加android-gif-drawable api
- 将 gif 放入可绘制文件夹中,然后像这样链接它:
layout/launch_screen.xml
这@drawable/tutorial
是我的 GIF,标题为tutorial.gif
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:background="@color/splashscreen_bg"
android:layout_height="match_parent">
<pl.droidsonroids.gif.GifImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/tutorial"
/>
</RelativeLayout>
样式.xml
我能够通过使用隐藏白屏闪光灯<item name="android:windowDisablePreview">true</item>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:textColor">#000000</item>
<!-- Add the following line to set the default status bar color for all the app. -->
<item name="android:statusBarColor">@color/app_bg</item>
<!-- Add the following line to set the default status bar text color for all the app
to be a light color (false) or a dark color (true) -->
<item name="android:windowLightStatusBar">false</item>
<!-- Add the following line to set the default background color for all the app. -->
<item name="android:windowBackground">@color/app_bg</item>
<!-- Prevents white screen from appearing when opening the app -->
<item name="android:windowDisablePreview">true</item>
</style>
</resources>
解决方案:iOS
- 使用静态徽标资产创建静态启动画面
- 启动后,使用徽标的动画版本渲染相同的屏幕
希望这对大家有帮助!
推荐阅读
- python - 通过多个可能的分隔符拆分字符串
- reactjs - Spring boot + JWT + Reactjs:POST API 出现 403 错误
- generics - 如何在泛型中声明对任何子程序形式类型的访问?
- javascript - 从使用状态更新后状态不变
- javascript - React Hook useState 值被重置为初始值
- mongodb - 如何在 deno 中模拟我的 mongodb 数据库/客户端?
- excel - 确实是网站网页抓取分页问题
- javascript - 试图获取嵌套信息但返回未定义
- php - 从 Laravel 7 在 MongoDB 中插入 Json 对象
- xml - 强制默认 ASP.NET 核心 xml 序列化程序序列化具有基类类型的对象