-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
539 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
'use strict'; | ||
|
||
var _extends = require('@babel/runtime/helpers/extends'); | ||
var React = require('react'); | ||
var reactNative = require('react-native'); | ||
|
||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
|
||
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends); | ||
var React__default = /*#__PURE__*/_interopDefaultLegacy(React); | ||
|
||
const resizeMode = { | ||
contain: 'contain', | ||
cover: 'cover', | ||
stretch: 'stretch', | ||
center: 'center' | ||
}; | ||
const priority = { | ||
low: 'low', | ||
normal: 'normal', | ||
high: 'high' | ||
}; | ||
const cacheControl = { | ||
// Ignore headers, use uri as cache key, fetch only if not in cache. | ||
immutable: 'immutable', | ||
// Respect http headers, no aggressive caching. | ||
web: 'web', | ||
// Only load from cache. | ||
cacheOnly: 'cacheOnly' | ||
}; | ||
|
||
const resolveDefaultSource = defaultSource => { | ||
if (!defaultSource) { | ||
return null; | ||
} | ||
|
||
if (reactNative.Platform.OS === 'android') { | ||
// Android receives a URI string, and resolves into a Drawable using RN's methods. | ||
const resolved = reactNative.Image.resolveAssetSource(defaultSource); | ||
|
||
if (resolved) { | ||
return resolved.uri; | ||
} | ||
|
||
return null; | ||
} // iOS or other number mapped assets | ||
// In iOS the number is passed, and bridged automatically into a UIImage | ||
|
||
|
||
return defaultSource; | ||
}; | ||
|
||
function FastImageBase({ | ||
source, | ||
defaultSource, | ||
tintColor, | ||
onLoadStart, | ||
onProgress, | ||
onLoad, | ||
onError, | ||
onLoadEnd, | ||
style, | ||
fallback, | ||
children, | ||
// eslint-disable-next-line no-shadow | ||
resizeMode = 'cover', | ||
forwardedRef, | ||
...props | ||
}) { | ||
if (fallback) { | ||
const cleanedSource = { ...source | ||
}; | ||
delete cleanedSource.cache; | ||
const resolvedSource = reactNative.Image.resolveAssetSource(cleanedSource); | ||
return /*#__PURE__*/React__default['default'].createElement(reactNative.View, { | ||
style: [styles.imageContainer, style], | ||
ref: forwardedRef | ||
}, /*#__PURE__*/React__default['default'].createElement(reactNative.Image, _extends__default['default']({}, props, { | ||
style: [reactNative.StyleSheet.absoluteFill, { | ||
tintColor | ||
}], | ||
source: resolvedSource, | ||
defaultSource: defaultSource, | ||
onLoadStart: onLoadStart, | ||
onProgress: onProgress, | ||
onLoad: onLoad, | ||
onError: onError, | ||
onLoadEnd: onLoadEnd, | ||
resizeMode: resizeMode | ||
})), children); | ||
} | ||
|
||
const resolvedSource = reactNative.Image.resolveAssetSource(source); | ||
const resolvedDefaultSource = resolveDefaultSource(defaultSource); | ||
return /*#__PURE__*/React__default['default'].createElement(reactNative.View, { | ||
style: [styles.imageContainer, style], | ||
ref: forwardedRef | ||
}, /*#__PURE__*/React__default['default'].createElement(FastImageView, _extends__default['default']({}, props, { | ||
tintColor: tintColor, | ||
style: reactNative.StyleSheet.absoluteFill, | ||
source: resolvedSource, | ||
defaultSource: resolvedDefaultSource, | ||
onFastImageLoadStart: onLoadStart, | ||
onFastImageProgress: onProgress, | ||
onFastImageLoad: onLoad, | ||
onFastImageError: onError, | ||
onFastImageLoadEnd: onLoadEnd, | ||
resizeMode: resizeMode | ||
})), children); | ||
} | ||
|
||
const FastImageMemo = /*#__PURE__*/React.memo(FastImageBase); | ||
const FastImageComponent = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React__default['default'].createElement(FastImageMemo, _extends__default['default']({ | ||
forwardedRef: ref | ||
}, props))); | ||
FastImageComponent.displayName = 'FastImage'; | ||
const FastImage = FastImageComponent; | ||
FastImage.resizeMode = resizeMode; | ||
FastImage.cacheControl = cacheControl; | ||
FastImage.priority = priority; | ||
|
||
FastImage.preload = sources => reactNative.NativeModules.FastImageView.preload(sources); | ||
|
||
FastImage.clearMemoryCache = () => reactNative.NativeModules.FastImageView.clearMemoryCache(); | ||
|
||
FastImage.clearDiskCache = () => reactNative.NativeModules.FastImageView.clearDiskCache(); | ||
|
||
const styles = reactNative.StyleSheet.create({ | ||
imageContainer: { | ||
overflow: 'hidden' | ||
} | ||
}); // Types of requireNativeComponent are not correct. | ||
|
||
const FastImageView = reactNative.requireNativeComponent('FastImageView', FastImage, { | ||
nativeOnly: { | ||
onFastImageLoadStart: true, | ||
onFastImageProgress: true, | ||
onFastImageLoad: true, | ||
onFastImageError: true, | ||
onFastImageLoadEnd: true | ||
} | ||
}); | ||
|
||
module.exports = FastImage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// @flow | ||
|
||
import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes' | ||
import type { SyntheticEvent } from 'react-native/Libraries/Types/CoreEventTypes' | ||
|
||
export type OnLoadEvent = SyntheticEvent< | ||
$ReadOnly<{ | ||
width: number, | ||
height: number, | ||
}>, | ||
> | ||
|
||
export type OnProgressEvent = SyntheticEvent< | ||
$ReadOnly<{| | ||
loaded: number, | ||
total: number, | ||
|}>, | ||
> | ||
|
||
export type ResizeMode = $ReadOnly<{| | ||
contain: 'contain', | ||
cover: 'cover', | ||
stretch: 'stretch', | ||
center: 'center', | ||
|}> | ||
|
||
export type Priority = $ReadOnly<{| | ||
low: 'low', | ||
normal: 'normal', | ||
high: 'high', | ||
|}> | ||
|
||
export type CacheControl = $ReadOnly<{| | ||
immutable: 'immutable', | ||
web: 'web', | ||
cacheOnly: 'cacheOnly', | ||
|}> | ||
|
||
export type ResizeModes = $Values<ResizeMode> | ||
export type Priorities = $Values<Priority> | ||
export type CacheControls = $Values<CacheControl> | ||
|
||
export type PreloadFn = (sources: Array<FastImageSource>) => void | ||
export type FastImageSource = { | ||
uri?: string, | ||
headers?: Object, | ||
priority?: Priorities, | ||
cache?: CacheControls, | ||
} | ||
|
||
export type FastImageProps = $ReadOnly<{| | ||
...ViewProps, | ||
onError?: ?() => void, | ||
onLoad?: ?(event: OnLoadEvent) => void, | ||
onLoadEnd?: ?() => void, | ||
onLoadStart?: ?() => void, | ||
onProgress?: ?(event: OnProgressEvent) => void, | ||
|
||
source?: ?(FastImageSource | number), | ||
defaultSource?: ?number, | ||
|
||
tintColor?: number | string, | ||
resizeMode?: ?ResizeModes, | ||
fallback?: ?boolean, | ||
testID?: ?string, | ||
|}> | ||
|
||
declare export default class FastImage extends React$Component<FastImageProps> { | ||
static resizeMode: ResizeMode; | ||
static priority: Priority; | ||
static cacheControl: CacheControl; | ||
static preload: PreloadFn; | ||
static clearMemoryCache: () => Promise<void>; | ||
static clearDiskCache: () => Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import React from 'react'; | ||
import { FlexStyle, LayoutChangeEvent, ShadowStyleIOS, StyleProp, TransformsStyle, ImageRequireSource, AccessibilityProps, ViewProps, ColorValue } from 'react-native'; | ||
export declare type ResizeMode = 'contain' | 'cover' | 'stretch' | 'center'; | ||
declare const resizeMode: { | ||
readonly contain: "contain"; | ||
readonly cover: "cover"; | ||
readonly stretch: "stretch"; | ||
readonly center: "center"; | ||
}; | ||
export declare type Priority = 'low' | 'normal' | 'high'; | ||
declare const priority: { | ||
readonly low: "low"; | ||
readonly normal: "normal"; | ||
readonly high: "high"; | ||
}; | ||
declare type Cache = 'immutable' | 'web' | 'cacheOnly'; | ||
declare const cacheControl: { | ||
readonly immutable: "immutable"; | ||
readonly web: "web"; | ||
readonly cacheOnly: "cacheOnly"; | ||
}; | ||
export declare type Source = { | ||
uri?: string; | ||
headers?: { | ||
[key: string]: string; | ||
}; | ||
priority?: Priority; | ||
cache?: Cache; | ||
}; | ||
export interface OnLoadEvent { | ||
nativeEvent: { | ||
width: number; | ||
height: number; | ||
}; | ||
} | ||
export interface OnProgressEvent { | ||
nativeEvent: { | ||
loaded: number; | ||
total: number; | ||
}; | ||
} | ||
export interface ImageStyle extends FlexStyle, TransformsStyle, ShadowStyleIOS { | ||
backfaceVisibility?: 'visible' | 'hidden'; | ||
borderBottomLeftRadius?: number; | ||
borderBottomRightRadius?: number; | ||
backgroundColor?: string; | ||
borderColor?: string; | ||
borderWidth?: number; | ||
borderRadius?: number; | ||
borderTopLeftRadius?: number; | ||
borderTopRightRadius?: number; | ||
overlayColor?: string; | ||
opacity?: number; | ||
} | ||
export interface FastImageProps extends AccessibilityProps, ViewProps { | ||
source?: Source | ImageRequireSource; | ||
defaultSource?: ImageRequireSource; | ||
resizeMode?: ResizeMode; | ||
fallback?: boolean; | ||
onLoadStart?(): void; | ||
onProgress?(event: OnProgressEvent): void; | ||
onLoad?(event: OnLoadEvent): void; | ||
onError?(): void; | ||
onLoadEnd?(): void; | ||
/** | ||
* onLayout function | ||
* | ||
* Invoked on mount and layout changes with | ||
* | ||
* {nativeEvent: { layout: {x, y, width, height}}}. | ||
*/ | ||
onLayout?: (event: LayoutChangeEvent) => void; | ||
/** | ||
* | ||
* Style | ||
*/ | ||
style?: StyleProp<ImageStyle>; | ||
/** | ||
* TintColor | ||
* | ||
* If supplied, changes the color of all the non-transparent pixels to the given color. | ||
*/ | ||
tintColor?: ColorValue; | ||
/** | ||
* A unique identifier for this element to be used in UI Automation testing scripts. | ||
*/ | ||
testID?: string; | ||
/** | ||
* Render children within the image. | ||
*/ | ||
children?: React.ReactNode; | ||
} | ||
export interface FastImageStaticProperties { | ||
resizeMode: typeof resizeMode; | ||
priority: typeof priority; | ||
cacheControl: typeof cacheControl; | ||
preload: (sources: Source[]) => void; | ||
clearMemoryCache: () => Promise<void>; | ||
clearDiskCache: () => Promise<void>; | ||
} | ||
declare const FastImage: React.ComponentType<FastImageProps> & FastImageStaticProperties; | ||
export default FastImage; | ||
//# sourceMappingURL=index.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.