android - 如何在 Expo eject 的启动画面中使用 SVG 图像

标签 android ios react-native svg expo

我使用“Expo 对象”分隔“Expo”。我想使用 SVG 来解析启动画面。但我不知道该怎么做。

我只知道如何在 Android 中使用图像。

我不知道 Ios 启动画面

Android(splash_backgroud.xml):

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@color/splashBackground"/>

    <item><bitmap android:gravity="center" android:src="@drawable/splash" /></item>

</layer-list>

androidimage

I created the file ic_splash.xml using the SVG image as drawable => NEW => Vector Asset.

但我不知道如何应用它。

我不知道如何处理 iPhone。

告诉我如何应用iPhone和Android。

请多多帮助我们。提前谢谢你。

最佳答案

我隐藏了基本的启动画面并使用了我制作的画面。

基本上,只有 png , jpeg扩展图片文件可在 Android 上获得和 ios .

例子.js

import React from 'react';
import { Image, Text, View } from 'react-native';
import { Asset, SplashScreen } from 'expo';
import SvgUri from "expo-svg-uri";

export default class App extends React.Component {
  state = {
    isReady: false,
  };

  componentDidMount() {
    SplashScreen.preventAutoHide();
  }

  render() {
    if (!this.state.isReady) {
      return (
        <View style={{ flex: 1 }}>
          <SvgUri
            width="200"
            height="200"
            source={require('./assets/images/splash.svg')}
            onLoad={this._cacheResourcesAsync}
          />
        </View>
      );
    }

    return (
      <View style={{ flex: 1 }}>
        <Image source={require('./assets/images/expo-icon.png')} />
        <Image source={require('./assets/images/slack-icon.png')} />
      </View>
    );    
  }


  _cacheResourcesAsync = async () => {
    SplashScreen.hide();
    const images = [
      require('./assets/images/expo-icon.png'),
      require('./assets/images/slack-icon.png'),
    ];

    const cacheImages = images.map((image) => {
      return Asset.fromModule(image).downloadAsync();
    });

    await Promise.all(cacheImages);
    this.setState({ isReady: true });
  }
}

关于android - 如何在 Expo eject 的启动画面中使用 SVG 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56179067/

相关文章:

android - 在 Android sdk 2.2 中的 SD 卡上安装应用程序

java - 如何使用 Proguard 或其他工具删除未使用的重写 toString() 方法?

android - Listview 快速滚动时跳到底部

ios - 从 "SecTrustCopyPublicKey"调用收到的值的含义

ios - 未找到签名证书 “iOS Development” - 使用 bitrise/FaSTLane 匹配构建应用程序版本

android - 在通知栏中更改远程 View 中的按钮背景

ios - 如何将我的项目从使用 Storyboard 转变为不再使用 Storyboard?

javascript - 存储和更新存储的对象

react-native - 发生配置项目 ':app' 。 > 未能通知项目评估监听器

android - 如何在Android上用react-native-push-notification获取所有通知,相当于PushNotificationIOS getDeliveredNotifications?