From 8dd16e4e5888015391b6364c806a1934c085ce3e Mon Sep 17 00:00:00 2001
From: Website Deployment Script
You can edit the content above on GitHub and send us a pull request!
Examples # | Edit on GitHub |
You can edit the content above on GitHub and send us a pull request!
Examples # | Edit on GitHub |
See CameraRoll for an example of
-using local resources that are outside of Images.xcassets.
iOS saves multiple sizes for the same image in your Camera Roll, it is very important to pick the one that's as close as possible for performance reasons. You wouldn't want to use the full quality 3264x2448 image as source when displaying a 200x200 thumbnail. If there's an exact match, React Native will pick it, otherwise it's going to use the first one that's at least 50% bigger in order to avoid blur when resizing from a close size. All of this is done by default so you don't have to worry about writing the tedious (and error prone) code to do it yourself.
In the browser if you don't give a size to an image, the browser is going to render a 0x0 element, download the image, and then render the image based with the correct size. The big issue with this behavior is that your UI is going to jump all around as images load, this makes for a very bad user experience.
In React Native this behavior is intentionally not implemented. It is more work for the developer to know the dimensions (or aspect ratio) of the remote image in advance, but we believe that it leads to a better user experience. Static images loaded from the app bundle via the require('./my-icon.png') syntax can be automatically sized because their dimensions are available immediately at the time of mounting.
For example, the result of require('./my-icon.png') might be:
In React Native, one interesting decision is that the src attribute is named source and doesn't take a string but an object with a uri attribute.
On the infrastructure side, the reason is that it allows us to attach metadata to this object. For example if you are using require('./my-icon.png'), then we add information about its actual location and size (don't rely on this fact, it might change in the future!). This is also future proofing, for example we may want to support sprites at some point, instead of outputting {uri: ...}, we can output {uri: ..., crop: {left: 10, top: 50, width: 20, height: 40}} and transparently support spriting on all the existing call sites.
On the user side, this lets you annotate the object with useful attributes such as the dimension of the image in order to compute the size it's going to be displayed in. Feel free to use it as your data structure to store more information about your image.
A common feature request from developers familiar with the web is background-image. To handle this use case, simply create a normal <Image> component and add whatever children to it you would like to layer on top of it.
Images.xcassets.iOS saves multiple sizes for the same image in your Camera Roll, it is very important to pick the one that's as close as possible for performance reasons. You wouldn't want to use the full quality 3264x2448 image as source when displaying a 200x200 thumbnail. If there's an exact match, React Native will pick it, otherwise it's going to use the first one that's at least 50% bigger in order to avoid blur when resizing from a close size. All of this is done by default so you don't have to worry about writing the tedious (and error prone) code to do it yourself.
In the browser if you don't give a size to an image, the browser is going to render a 0x0 element, download the image, and then render the image based with the correct size. The big issue with this behavior is that your UI is going to jump all around as images load, this makes for a very bad user experience.
In React Native this behavior is intentionally not implemented. It is more work for the developer to know the dimensions (or aspect ratio) of the remote image in advance, but we believe that it leads to a better user experience. Static images loaded from the app bundle via the require('./my-icon.png') syntax can be automatically sized because their dimensions are available immediately at the time of mounting.
For example, the result of require('./my-icon.png') might be:
In React Native, one interesting decision is that the src attribute is named source and doesn't take a string but an object with a uri attribute.
On the infrastructure side, the reason is that it allows us to attach metadata to this object. For example if you are using require('./my-icon.png'), then we add information about its actual location and size (don't rely on this fact, it might change in the future!). This is also future proofing, for example we may want to support sprites at some point, instead of outputting {uri: ...}, we can output {uri: ..., crop: {left: 10, top: 50, width: 20, height: 40}} and transparently support spriting on all the existing call sites.
On the user side, this lets you annotate the object with useful attributes such as the dimension of the image in order to compute the size it's going to be displayed in. Feel free to use it as your data structure to store more information about your image.
A common feature request from developers familiar with the web is background-image. To handle this use case, simply create a normal <Image> component and add whatever children to it you would like to layer on top of it.
tail - The line is displayed so that the beginning fits in the container and the
missing text at the end of the line is indicated by an ellipsis glyph. e.g., "abcd..."clip - Lines are not drawn past the edge of the text container.The default is tail.
numberOfLines must be set in conjunction with this prop.
clipis working only for iOS
Used to truncate the text with an ellipsis after computing the text layout, including line wrapping, such that the total number of lines -does not exceed this number.
This prop is commonly used with ellipsizeMode.
Invoked on mount and layout changes with
{nativeEvent: {layout: {x, y, width, height}}}
This function is called on long press.
e.g., `onLongPress={this.increaseSize}>``
This function is called on press.
e.g., `onPress={() => console.log('1st')}``
This prop is commonly used with ellipsizeMode.
Invoked on mount and layout changes with
{nativeEvent: {layout: {x, y, width, height}}}
This function is called on long press.
e.g., `onLongPress={this.increaseSize}>``
This function is called on press.
e.g., `onPress={() => console.log('1st')}``
Specifies font weight. The values 'normal' and 'bold' are supported for @@ -582,6 +590,33 @@ exports.examples /View> ); }, +}, { + title: 'Font variants', + render: function() { + return ( + <View> + <Text style={{fontVariant: ['small-caps']}}> + Small Caps{'\n'} + </Text> + <Text style={{fontFamily: 'Hoefler Text', fontVariant: ['oldstyle-nums']}}> + Old Style nums 0123456789{'\n'} + </Text> + <Text style={{fontFamily: 'Hoefler Text', fontVariant: ['lining-nums']}}> + Lining nums 0123456789{'\n'} + </Text> + <Text style={{fontVariant: ['tabular-nums']}}> + Tabular nums{'\n'} + 1111{'\n'} + 2222{'\n'} + </Text> + <Text style={{fontVariant: ['proportional-nums']}}> + Proportional nums{'\n'} + 1111{'\n'} + 2222{'\n'} + </Text> + </View> + ); + }, }]; var styles = StyleSheet.create({