From 2be273ad936f53e966745bf8d0d1b5f7352d0ef1 Mon Sep 17 00:00:00 2001 From: Travis CI Date: Wed, 3 Jun 2015 18:14:57 +0000 Subject: [PATCH] update website --- docs/netinfo.html | 39 ++++++--------------------------------- docs/pixelratio.html | 5 ++++- 2 files changed, 10 insertions(+), 34 deletions(-) diff --git a/docs/netinfo.html b/docs/netinfo.html index b6eb58b19ff..aab5c81c712 100644 --- a/docs/netinfo.html +++ b/docs/netinfo.html @@ -1,31 +1,4 @@ -React Native | A framework for building native apps using React

NetInfo

NetInfo exposes info about online/offline status

reachabilityIOS #

Asynchronously determine if the device is online and on a cellular network.

  • none - device is offline
  • wifi - device is online and connected via wifi, or is the iOS simulator
  • cell - device is connected via Edge, 3G, WiMax, or LTE
  • unknown - error case and the network status is unknown
NetInfo.reachabilityIOS.fetch().done((reach) => { - console.log('Initial: ' + reach); -}); -function handleFirstReachabilityChange(reach) { - console.log('First change: ' + reach); - NetInfo.reachabilityIOS.removeEventListener( - 'change', - handleFirstReachabilityChange - ); -} -NetInfo.reachabilityIOS.addEventListener( - 'change', - handleFirstReachabilityChange -);

isConnected #

Available on all platforms. Asynchronously fetch a boolean to determine -internet connectivity.

NetInfo.isConnected.fetch().done((isConnected) => { - console.log('First, is ' + (isConnected ? 'online' : 'offline')); -}); -function handleFirstConnectivityChange(isConnected) { - console.log('Then, is ' + (isConnected ? 'online' : 'offline')); - NetInfo.isConnected.removeEventListener( - 'change', - handleFirstConnectivityChange - ); -} -NetInfo.isConnected.addEventListener( - 'change', - handleFirstConnectivityChange -);

Edit on GitHubExamples #

'use strict'; +React Native | A framework for building native apps using React

NetInfo

Methods #

static addEventListener(eventName: ChangeEventName, handler: Function) #

static removeEventListener(eventName: ChangeEventName, handler: Function) #

static fetch() #

Edit on GitHubExamples #

'use strict'; var React = require('react-native'); var { @@ -41,13 +14,13 @@ NetInfo.isConnected}; }, componentDidMount: function() { - NetInfo.reachabilityIOS.addEventListener( + NetInfo.addEventListener( 'change', this._handleReachabilityChange ); }, componentWillUnmount: function() { - NetInfo.reachabilityIOS.removeEventListener( + NetInfo.removeEventListener( 'change', this._handleReachabilityChange ); @@ -75,16 +48,16 @@ NetInfo.isConnected}; }, componentDidMount: function() { - NetInfo.reachabilityIOS.addEventListener( + NetInfo.addEventListener( 'change', this._handleReachabilityChange ); - NetInfo.reachabilityIOS.fetch().done( + NetInfo.fetch().done( (reachability) => { this.setState({reachability}); } ); }, componentWillUnmount: function() { - NetInfo.reachabilityIOS.removeEventListener( + NetInfo.removeEventListener( 'change', this._handleReachabilityChange ); diff --git a/docs/pixelratio.html b/docs/pixelratio.html index b5c7aa1f04a..2ed9ccf2b84 100644 --- a/docs/pixelratio.html +++ b/docs/pixelratio.html @@ -6,7 +6,10 @@ by the pixel ratio.

: PixelRatio.getPixelSizeForLayoutSize(200), height: PixelRatio.getPixelSizeForLayoutSize(100), }); -<Image source={image} style={{width: 200, height: 100}} />

Methods #

static get() #

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
  • PixelRatio.get() === 3.5
    • Nexus 6

static getPixelSizeForLayoutSize(layoutSize: number) #

Converts a layout size (dp) to pixel size (px).

Guaranteed to return an integer number.

static startDetecting() #

// No-op for iOS, but used on the web. Should not be documented.

Edit on GitHubDescription #

Pixel Grid Snapping #

In iOS, you can specify positions and dimensions for elements with arbitrary precision, for example 29.674825. But, ultimately the physical display only have a fixed number of pixels, for example 640×960 for iphone 4 or 750×1334 for iphone 6. iOS tries to be as faithful as possible to the user value by spreading one original pixel into multiple ones to trick the eye. The downside of this technique is that it makes the resulting element look blurry.

In practice, we found out that developers do not want this feature and they have to work around it by doing manual rounding in order to avoid having blurry elements. In React Native, we are rounding all the pixels automatically.

We have to be careful when to do this rounding. You never want to work with rounded and unrounded values at the same time as you're going to accumulate rounding errors. Having even one rounding error is deadly because a one pixel border may vanish or be twice as big.

In React Native, everything in JS and within the layout engine work with arbitrary precision numbers. It's only when we set the position and dimensions of the native element on the main thread that we round. Also, rounding is done relative to the root rather than the parent, again to avoid accumulating rounding errors.

© 2015 Facebook Inc.