From 0ad814c52966da6bdce200e508a33feccd1216d9 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Mon, 15 Oct 2018 13:17:12 -0700 Subject: [PATCH] Export assets for easy caching in Expo --- example/App.js | 15 +++++++-------- src/index.js | 10 ++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/example/App.js b/example/App.js index 97dc39d..45bbf06 100644 --- a/example/App.js +++ b/example/App.js @@ -1,8 +1,11 @@ import React from 'react'; import Expo from 'expo'; import { FlatList, I18nManager } from 'react-native'; -import { createSwitchNavigator } from '@react-navigation/core'; -import { createStackNavigator } from 'react-navigation-stack'; +import { createSwitchNavigator } from 'react-navigation'; +import { + Assets as StackAssets, + createStackNavigator, +} from 'react-navigation-stack'; import { ListSection, Divider } from 'react-native-paper'; import SimpleStack from './src/SimpleStack'; @@ -41,12 +44,8 @@ const data = [ }, ]; -Expo.Asset.loadAsync( - require('react-navigation/src/views/assets/back-icon.png') -); -Expo.Asset.loadAsync( - require('react-navigation/src/views/assets/back-icon-mask.png') -); +// Cache images +Expo.Asset.loadAsync(StackAssets); class Home extends React.Component { static navigationOptions = { diff --git a/src/index.js b/src/index.js index 2e72c50..85a75e6 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,5 @@ /* eslint-disable import/no-commonjs */ +import { Platform } from 'react-native'; module.exports = { /** @@ -11,6 +12,15 @@ module.exports = { /** * Views */ + get Assets() { + return Platform.select({ + ios: [ + require('./views/assets/back-icon.png'), + require('./views/assets/back-icon-mask.png'), + ], + android: [require('./views/assets/back-icon.png')], + }); + }, get Header() { return require('./views/Header/Header').default; },