DylanVann / react-native-fast-image

Compare 6255fc4 ... +1 ... ec7c453

Coverage Reach
index.tsx

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -10,12 +10,12 @@
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
17 -
const FastImageViewNativeModule = NativeModules.FastImageView
18 -
19 19
export type ResizeMode = 'contain' | 'cover' | 'stretch' | 'center'
20 20
21 21
const resizeMode = {
@@ -81,7 +81,8 @@
Loading
81 81
}
82 82
83 83
export interface FastImageProps extends AccessibilityProps, ViewProps {
84 -
    source: Source | number
84 +
    source?: Source | ImageRequireSource
85 +
    defaultSource?: ImageRequireSource
85 86
    resizeMode?: ResizeMode
86 87
    fallback?: boolean
87 88
@@ -129,8 +130,32 @@
Loading
129 130
    children?: React.ReactNode
130 131
}
131 132
133 +
const resolveDefaultSource = (
134 +
    defaultSource?: ImageRequireSource,
135 +
): string | number | null => {
136 +
    if (!defaultSource) {
137 +
        return null
138 +
    }
139 +
    if (Platform.OS === 'android') {
140 +
        // Android receives a URI string, and resolves into a Drawable using RN's methods.
141 +
        const resolved = Image.resolveAssetSource(
142 +
            defaultSource as ImageRequireSource,
143 +
        )
144 +
145 +
        if (resolved) {
146 +
            return resolved.uri
147 +
        }
148 +
149 +
        return null
150 +
    }
151 +
    // iOS or other number mapped assets
152 +
    // In iOS the number is passed, and bridged automatically into a UIImage
153 +
    return defaultSource
154 +
}
155 +
132 156
function FastImageBase({
133 157
    source,
158 +
    defaultSource,
134 159
    tintColor,
135 160
    onLoadStart,
136 161
    onProgress,
@@ -156,6 +181,7 @@
Loading
156 181
                    {...props}
157 182
                    style={StyleSheet.absoluteFill}
158 183
                    source={resolvedSource}
184 +
                    defaultSource={defaultSource}
159 185
                    onLoadStart={onLoadStart}
160 186
                    onProgress={onProgress}
161 187
                    onLoad={onLoad as any}
@@ -169,6 +195,7 @@
Loading
169 195
    }
170 196
171 197
    const resolvedSource = Image.resolveAssetSource(source as any)
198 +
    const resolvedDefaultSource = resolveDefaultSource(defaultSource)
172 199
173 200
    return (
174 201
        <View style={[styles.imageContainer, style]} ref={forwardedRef}>
@@ -177,6 +204,7 @@
Loading
177 204
                tintColor={tintColor}
178 205
                style={StyleSheet.absoluteFill}
179 206
                source={resolvedSource}
207 +
                defaultSource={resolvedDefaultSource}
180 208
                onFastImageLoadStart={onLoadStart}
181 209
                onFastImageProgress={onProgress}
182 210
                onFastImageLoad={onLoad}
@@ -218,11 +246,12 @@
Loading
218 246
FastImage.priority = priority
219 247
220 248
FastImage.preload = (sources: Source[]) =>
221 -
    FastImageViewNativeModule.preload(sources)
249 +
    NativeModules.FastImageView.preload(sources)
222 250
223 -
FastImage.clearMemoryCache = () => FastImageViewNativeModule.clearMemoryCache()
251 +
FastImage.clearMemoryCache = () =>
252 +
    NativeModules.FastImageView.clearMemoryCache()
224 253
225 -
FastImage.clearDiskCache = () => FastImageViewNativeModule.clearDiskCache()
254 +
FastImage.clearDiskCache = () => NativeModules.FastImageView.clearDiskCache()
226 255
227 256
const styles = StyleSheet.create({
228 257
    imageContainer: {

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
src/index.tsx +3.70% 100.00%
Project Totals (1 files) 100.00%
Loading