Skip to content

Commit

Permalink
chore(build): Add build files to the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
abdallaayman21 committed Sep 26, 2024
1 parent 5b3c0c0 commit 0c39f4a
Show file tree
Hide file tree
Showing 9 changed files with 538 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ example/android/app/src/main/gen

# build
react-native-fast-image-*.tgz
dist/

# coverage reports
coverage
Expand Down
144 changes: 144 additions & 0 deletions dist/index.cjs.js
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;
75 changes: 75 additions & 0 deletions dist/index.cjs.js.flow
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>;
}
103 changes: 103 additions & 0 deletions dist/index.d.ts
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
1 change: 1 addition & 0 deletions dist/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0c39f4a

Please sign in to comment.