Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit 31c7038

Browse files
committed
Patching image source prop on render to use local file.
1 parent 5d5d461 commit 31c7038

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/imageCacheHoc.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
// Load dependencies.
1717
import React from 'react';
18-
import { ViewPropTypes } from 'react-native';
18+
import { Platform, ViewPropTypes } from 'react-native';
1919
import PropTypes from 'prop-types';
2020
import FileSystemFactory, { FileSystem } from '../lib/FileSystem';
2121
import traverse from 'traverse';
@@ -183,10 +183,13 @@ export default function imageCacheHoc(Image, options = {}) {
183183
// If media loaded, render full image component, else render placeholder.
184184
if (this.state.localFilePath) {
185185

186+
// Build platform specific file resource uri.
187+
const localFileUri = (Platform.OS == 'ios') ? this.state.localFilePath : 'file://' + this.state.localFilePath; // Android requires the traditional 3 prefixed slashes file:/// in a localhost absolute file uri.
188+
186189
// Extract props proprietary to this HOC before passing props through.
187190
let { permanent, ...filteredProps } = this.props; // eslint-disable-line no-unused-vars
188191

189-
let props = Object.assign({}, filteredProps, { uri: this.state.localFilePath });
192+
let props = Object.assign({}, filteredProps, { source: { uri: localFileUri } });
190193
return (<Image {...props} />);
191194
} else {
192195

0 commit comments

Comments
 (0)