mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-26 05:15:49 +08:00
Updates from Mon 16 Mar
- [ReactNative] Share same server port for debugger proxy | Alex Kotliarskyi - [react-packager] small fixes to image loader | Amjad Masad - [ReactNative] NetworkInformation.reachability API w/ example | Eric Vicenti - [ReactNative] Put launchOptions in RCTPushNotificationManager | Andrew Rasmussen - [ReactNative] Improve PixelRatio documentation | Christopher Chedeau
This commit is contained in:
@@ -10,45 +10,49 @@ var Dimensions = require('Dimensions');
|
||||
/**
|
||||
* PixelRatio class gives access to the device pixel density.
|
||||
*
|
||||
* Some examples:
|
||||
* - PixelRatio.get() === 2
|
||||
* - iPhone 4, 4S
|
||||
* - iPhone 5, 5c, 5s
|
||||
* - iPhone 6
|
||||
*
|
||||
* - PixelRatio.get() === 3
|
||||
* - iPhone 6 plus
|
||||
*
|
||||
* There are a few use cases for using PixelRatio:
|
||||
*
|
||||
* == Displaying a line that's as thin as the device permits
|
||||
* ### Displaying a line that's as thin as the device permits
|
||||
*
|
||||
* A width of 1 is actually pretty thick on an iPhone 4+, we can do one that's
|
||||
* thinner using a width of 1 / PixelRatio.get(). It's a technique that works
|
||||
* thinner using a width of `1 / PixelRatio.get()`. It's a technique that works
|
||||
* on all the devices independent of their pixel density.
|
||||
*
|
||||
* style={{ borderWidth: 1 / PixelRatio.get() }}
|
||||
* ```
|
||||
* style={{ borderWidth: 1 / PixelRatio.get() }}
|
||||
* ```
|
||||
*
|
||||
* == Fetching a correctly sized image
|
||||
* ### Fetching a correctly sized image
|
||||
*
|
||||
* You should get a higher resolution image if you are on a high pixel density
|
||||
* device. A good rule of thumb is to multiply the size of the image you display
|
||||
* by the pixel ratio.
|
||||
*
|
||||
* var image = getImage({
|
||||
* width: 200 * PixelRatio.get(),
|
||||
* height: 100 * PixelRatio.get()
|
||||
* });
|
||||
* <Image source={image} style={{width: 200, height: 100}} />
|
||||
* ```
|
||||
* var image = getImage({
|
||||
* width: 200 * PixelRatio.get(),
|
||||
* height: 100 * PixelRatio.get()
|
||||
* });
|
||||
* <Image source={image} style={{width: 200, height: 100}} />
|
||||
* ```
|
||||
*/
|
||||
class PixelRatio {
|
||||
/**
|
||||
* Returns the device pixel density. Some examples:
|
||||
*
|
||||
* - PixelRatio.get() === 2
|
||||
* - iPhone 4, 4S
|
||||
* - iPhone 5, 5c, 5s
|
||||
* - iPhone 6
|
||||
* - PixelRatio.get() === 3
|
||||
* - iPhone 6 plus
|
||||
*/
|
||||
static get() {
|
||||
return Dimensions.get('window').scale;
|
||||
}
|
||||
}
|
||||
|
||||
static startDetecting() {
|
||||
// no-op for iOS, but this is useful for other platforms
|
||||
}
|
||||
};
|
||||
// No-op for iOS, but used on the web. Should not be documented.
|
||||
PixelRatio.startDetecting = function() {};
|
||||
|
||||
module.exports = PixelRatio;
|
||||
|
||||
@@ -5,8 +5,14 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var NativeModules = require('NativeModules');
|
||||
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
|
||||
|
||||
var RCTPushNotificationManager = NativeModules.RCTPushNotificationManager;
|
||||
if (RCTPushNotificationManager) {
|
||||
var _initialNotification = RCTPushNotificationManager.initialNotification;
|
||||
}
|
||||
|
||||
var _notifHandlers = {};
|
||||
|
||||
var DEVICE_NOTIF_EVENT = 'remoteNotificationReceived';
|
||||
@@ -30,6 +36,14 @@ class PushNotificationIOS {
|
||||
_notifHandlers[handler] = null;
|
||||
}
|
||||
|
||||
|
||||
static popInitialNotification() {
|
||||
var initialNotification = _initialNotification &&
|
||||
new PushNotificationIOS(_initialNotification);
|
||||
_initialNotification = null;
|
||||
return initialNotification;
|
||||
}
|
||||
|
||||
constructor(nativeNotif) {
|
||||
this._data = {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user