DylanVann / react-native-fast-image

@@ -10,10 +10,14 @@
Loading
10 10
    ShadowStyleIOS,
11 11
    StyleProp,
12 12
    TransformsStyle,
13 +
    ImageRequireSource,
14 +
    Platform,
13 15
    AccessibilityProps,
14 16
    ViewProps,
15 17
} from 'react-native'
16 18
19 +
const isAndroid = Platform.OS === 'android'
20 +
17 21
const FastImageViewNativeModule = NativeModules.FastImageView
18 22
19 23
export type ResizeMode = 'contain' | 'cover' | 'stretch' | 'center'
@@ -81,7 +85,8 @@
Loading
81 85
}
82 86
83 87
export interface FastImageProps extends AccessibilityProps, ViewProps {
84 -
    source: Source | number
88 +
    source?: Source | ImageRequireSource
89 +
    defaultSource?: ImageRequireSource
85 90
    resizeMode?: ResizeMode
86 91
    fallback?: boolean
87 92
@@ -129,8 +134,32 @@
Loading
129 134
    children?: React.ReactNode
130 135
}
131 136
137 +
const resolveDefaultSource = (
138 +
    defaultSource?: ImageRequireSource,
139 +
): string | number | null => {
140 +
    if (!defaultSource) {
141 +
        return null
142 +
    }
143 +
    if (isAndroid) {
144 +
        // Android receives a URI string, and resolves into a Drawable using RN's methods.
145 +
        const resolved = Image.resolveAssetSource(
146 +
            defaultSource as ImageRequireSource,
147 +
        )
148 +
149 +
        if (resolved) {
150 +
            return resolved.uri
151 +
        }
152 +
153 +
        return null
154 +
    }
155 +
    // iOS or other number mapped assets
156 +
    // In iOS the number is passed, and bridged automatically into a UIImage
157 +
    return defaultSource
158 +
}
159 +
132 160
function FastImageBase({
133 161
    source,
162 +
    defaultSource,
134 163
    tintColor,
135 164
    onLoadStart,
136 165
    onProgress,
@@ -156,6 +185,7 @@
Loading
156 185
                    {...props}
157 186
                    style={StyleSheet.absoluteFill}
158 187
                    source={resolvedSource}
188 +
                    defaultSource={defaultSource}
159 189
                    onLoadStart={onLoadStart}
160 190
                    onProgress={onProgress}
161 191
                    onLoad={onLoad as any}
@@ -169,6 +199,7 @@
Loading
169 199
    }
170 200
171 201
    const resolvedSource = Image.resolveAssetSource(source as any)
202 +
    const resolvedDefaultSource = resolveDefaultSource(defaultSource)
172 203
173 204
    return (
174 205
        <View style={[styles.imageContainer, style]} ref={forwardedRef}>
@@ -177,6 +208,7 @@
Loading
177 208
                tintColor={tintColor}
178 209
                style={StyleSheet.absoluteFill}
179 210
                source={resolvedSource}
211 +
                defaultSource={resolvedDefaultSource}
180 212
                onFastImageLoadStart={onLoadStart}
181 213
                onFastImageProgress={onProgress}
182 214
                onFastImageLoad={onLoad}
Files Coverage
src/index.tsx 82.05%
Project Totals (1 files) 82.05%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading