Skip to content

Commit 3a33bda

Browse files
committed
🔘 Add border radius support to android and refactor and update examples.
1 parent 737452b commit 3a33bda

14 files changed

+474
-180
lines changed

FastImage.js

+45-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import React, { Component } from 'react'
22
import PropTypes from 'prop-types'
33
import {
4+
View,
45
Image,
56
NativeModules,
67
requireNativeComponent,
78
ViewPropTypes,
9+
StyleSheet,
810
} from 'react-native'
911

1012
const resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource')
@@ -24,6 +26,9 @@ class FastImage extends Component {
2426
onLoad,
2527
onError,
2628
onLoadEnd,
29+
style,
30+
children,
31+
borderRadius,
2732
...props
2833
} = this.props
2934

@@ -44,21 +49,51 @@ class FastImage extends Component {
4449
}
4550

4651
const resolvedSource = resolveAssetSource(source)
52+
53+
if (!children && !borderRadius) {
54+
return (
55+
<FastImageView
56+
ref={e => (this._root = e)}
57+
{...props}
58+
style={style}
59+
source={resolvedSource}
60+
onFastImageLoadStart={onLoadStart}
61+
onFastImageProgress={onProgress}
62+
onFastImageLoad={onLoad}
63+
onFastImageError={onError}
64+
onFastImageLoadEnd={onLoadEnd}
65+
/>
66+
)
67+
}
68+
4769
return (
48-
<FastImageView
49-
ref={e => (this._root = e)}
50-
{...props}
51-
source={resolvedSource}
52-
onFastImageLoadStart={onLoadStart}
53-
onFastImageProgress={onProgress}
54-
onFastImageLoad={onLoad}
55-
onFastImageError={onError}
56-
onFastImageLoadEnd={onLoadEnd}
57-
/>
70+
<View style={style} borderRadius={borderRadius}>
71+
<View style={styles.imageContainer} borderRadius={borderRadius}>
72+
<FastImageView
73+
ref={e => (this._root = e)}
74+
{...props}
75+
style={StyleSheet.absoluteFill}
76+
source={resolvedSource}
77+
onFastImageLoadStart={onLoadStart}
78+
onFastImageProgress={onProgress}
79+
onFastImageLoad={onLoad}
80+
onFastImageError={onError}
81+
onFastImageLoadEnd={onLoadEnd}
82+
/>
83+
</View>
84+
{children}
85+
</View>
5886
)
5987
}
6088
}
6189

90+
const styles = StyleSheet.create({
91+
imageContainer: {
92+
...StyleSheet.absoluteFillObject,
93+
overflow: 'hidden',
94+
},
95+
})
96+
6297
FastImage.resizeMode = {
6398
contain: 'contain',
6499
cover: 'cover',

example/App.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React from 'react'
22
import { TabNavigator, TabBarBottom } from 'react-navigation'
3-
import FastImageExample from './fastImage/FastImageExample'
3+
import FastImageExamples from './fastImage/FastImageExamples'
44
import FastImageGrid from './fastImage/FastImageGrid'
55
import DefaultImageGrid from './fastImage/DefaultImageGrid'
66

77
const App = TabNavigator(
88
{
99
fastImageExample: {
10-
screen: FastImageExample,
10+
screen: FastImageExamples,
1111
},
1212
image: {
1313
screen: DefaultImageGrid,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from 'react'
2+
import { StyleSheet, View } from 'react-native'
3+
import withCacheBust from './withCacheBust'
4+
import SectionFlex from './SectionFlex'
5+
import FastImage from 'react-native-fast-image'
6+
import Section from './Section'
7+
import FeatureText from './FeatureText'
8+
9+
const IMAGE_URL = 'https://media.giphy.com/media/GEsoqZDGVoisw/giphy.gif'
10+
const PLUS_IMAGE_URL =
11+
'https://cdn3.iconfinder.com/data/icons/block/32/add-512.png'
12+
13+
const BorderRadiusAndChildrenExample = ({ onPressReload, bust }) => (
14+
<View>
15+
<Section>
16+
<FeatureText text="• Border radius + children." />
17+
</Section>
18+
<SectionFlex onPress={onPressReload}>
19+
<FastImage
20+
style={styles.image}
21+
borderRadius={100}
22+
source={{
23+
uri: IMAGE_URL + bust,
24+
}}
25+
>
26+
<FastImage style={styles.plus} source={{ uri: PLUS_IMAGE_URL }} />
27+
</FastImage>
28+
</SectionFlex>
29+
</View>
30+
)
31+
32+
const styles = StyleSheet.create({
33+
image: {
34+
height: 100,
35+
backgroundColor: '#ddd',
36+
margin: 20,
37+
width: 100,
38+
flex: 0,
39+
},
40+
plus: {
41+
width: 30,
42+
height: 30,
43+
position: 'absolute',
44+
bottom: 0,
45+
right: 0,
46+
},
47+
})
48+
49+
export default withCacheBust(BorderRadiusAndChildrenExample)

example/fastImage/Button.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react'
2+
import { Text, TouchableOpacity, StyleSheet } from 'react-native'
3+
4+
const Button = ({ text, onPress }) => (
5+
<TouchableOpacity onPress={onPress}>
6+
<Text style={styles.button}>{text}</Text>
7+
</TouchableOpacity>
8+
)
9+
10+
const styles = StyleSheet.create({
11+
button: {
12+
backgroundColor: 'black',
13+
color: 'white',
14+
margin: 5,
15+
padding: 5,
16+
paddingLeft: 10,
17+
paddingRight: 10,
18+
borderRadius: 2,
19+
},
20+
})
21+
22+
export default Button

example/fastImage/FastImageExample.js

-168
This file was deleted.

0 commit comments

Comments
 (0)