mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-05 19:24:21 +00:00
[add] new Image resize modes
This commit is contained in:
@@ -46,7 +46,7 @@ Invoked when load either succeeds or fails,
|
|||||||
|
|
||||||
Invoked on load start.
|
Invoked on load start.
|
||||||
|
|
||||||
**resizeMode**: oneOf('contain', 'cover', 'none', 'stretch') = 'stretch'
|
**resizeMode**: oneOf('center', 'contain', 'cover', 'none', 'repeat', 'stretch') = 'stretch'
|
||||||
|
|
||||||
Determines how to resize the image when the frame doesn't match the raw image
|
Determines how to resize the image when the frame doesn't match the raw image
|
||||||
dimensions.
|
dimensions.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { storiesOf, action } from '@kadira/storybook';
|
import { storiesOf, action, addDecorator } from '@kadira/storybook';
|
||||||
import { ActivityIndicator, Image, Platform, StyleSheet, Text, View } from 'react-native'
|
import { ActivityIndicator, Image, Platform, StyleSheet, Text, View } from 'react-native'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -499,30 +499,26 @@ const examples = [
|
|||||||
source={image}
|
source={image}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
{ Platform.OS === 'ios' ?
|
<View style={styles.leftMargin}>
|
||||||
<View style={styles.leftMargin}>
|
<Text style={[styles.resizeModeText]}>
|
||||||
<Text style={[styles.resizeModeText]}>
|
Repeat
|
||||||
Repeat
|
</Text>
|
||||||
</Text>
|
<Image
|
||||||
<Image
|
style={styles.resizeMode}
|
||||||
style={styles.resizeMode}
|
resizeMode={'repeat'}
|
||||||
resizeMode={Image.resizeMode.repeat}
|
source={image}
|
||||||
source={image}
|
/>
|
||||||
/>
|
</View>
|
||||||
</View>
|
<View style={styles.leftMargin}>
|
||||||
: null }
|
<Text style={[styles.resizeModeText]}>
|
||||||
{ Platform.OS === 'android' ?
|
Center
|
||||||
<View style={styles.leftMargin}>
|
</Text>
|
||||||
<Text style={[styles.resizeModeText]}>
|
<Image
|
||||||
Center
|
style={styles.resizeMode}
|
||||||
</Text>
|
resizeMode={'center'}
|
||||||
<Image
|
source={image}
|
||||||
style={styles.resizeMode}
|
/>
|
||||||
resizeMode={Image.resizeMode.center}
|
</View>
|
||||||
source={image}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
: null }
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
@@ -654,5 +650,6 @@ var styles = StyleSheet.create({
|
|||||||
|
|
||||||
examples.forEach((example) => {
|
examples.forEach((example) => {
|
||||||
storiesOf('<Image>', module)
|
storiesOf('<Image>', module)
|
||||||
|
.addDecorator((renderStory) => <View>{renderStory()}</View>)
|
||||||
.add(example.title, () => example.render())
|
.add(example.title, () => example.render())
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import keyMirror from 'fbjs/lib/keyMirror'
|
import keyMirror from 'fbjs/lib/keyMirror'
|
||||||
|
|
||||||
const ImageResizeMode = keyMirror({
|
const ImageResizeMode = keyMirror({
|
||||||
|
center: null,
|
||||||
contain: null,
|
contain: null,
|
||||||
cover: null,
|
cover: null,
|
||||||
none: null,
|
none: null,
|
||||||
|
repeat: null,
|
||||||
stretch: null
|
stretch: null
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Image extends Component {
|
|||||||
onLoad: PropTypes.func,
|
onLoad: PropTypes.func,
|
||||||
onLoadEnd: PropTypes.func,
|
onLoadEnd: PropTypes.func,
|
||||||
onLoadStart: PropTypes.func,
|
onLoadStart: PropTypes.func,
|
||||||
resizeMode: PropTypes.oneOf(['contain', 'cover', 'none', 'stretch']),
|
resizeMode: PropTypes.oneOf(['center', 'contain', 'cover', 'none', 'repeat', 'stretch']),
|
||||||
source: ImageSourcePropType,
|
source: ImageSourcePropType,
|
||||||
style: StyleSheetPropType(ImageStylePropTypes),
|
style: StyleSheetPropType(ImageStylePropTypes),
|
||||||
testID: createReactDOMComponent.propTypes.testID
|
testID: createReactDOMComponent.propTypes.testID
|
||||||
@@ -207,6 +207,10 @@ const styles = StyleSheet.create({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const resizeModeStyles = StyleSheet.create({
|
const resizeModeStyles = StyleSheet.create({
|
||||||
|
center: {
|
||||||
|
backgroundSize: 'auto',
|
||||||
|
backgroundPosition: 'center'
|
||||||
|
},
|
||||||
contain: {
|
contain: {
|
||||||
backgroundSize: 'contain'
|
backgroundSize: 'contain'
|
||||||
},
|
},
|
||||||
@@ -216,6 +220,10 @@ const resizeModeStyles = StyleSheet.create({
|
|||||||
none: {
|
none: {
|
||||||
backgroundSize: 'auto'
|
backgroundSize: 'auto'
|
||||||
},
|
},
|
||||||
|
repeat: {
|
||||||
|
backgroundSize: 'auto',
|
||||||
|
backgroundRepeat: 'repeat'
|
||||||
|
},
|
||||||
stretch: {
|
stretch: {
|
||||||
backgroundSize: '100% 100%'
|
backgroundSize: '100% 100%'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user