NativeMethodsMixin

NativeMethodsMixin

//* NativeMethodsMixin provides methods to access the underlying native component directly. This can be useful in cases when you want to focus a view or measure its on-screen dimensions, for example.

The methods described here are available on most of the default components provided by React Native. Note, however, that they are not available on composite components that aren't directly backed by a native view. This will generally include most components that you define in your own app. For more information, see Direct Manipulation.

// TODO (bvaughn) Figure out how to use the NativeMethodsInterface type to- // ensure that these mixins and ReactNativeFiberHostComponent stay in sync. // Unfortunately, using it causes Flow to complain WRT createClass mixins: // "call of method createClass. Expected an exact object instead of ..."

Methods

static measure(callback)

Determines the location on screen, width, and height of the given view and returns the values via an async callback. If successful, the callback will be called with the following arguments:

  • x
  • y
  • width
  • height
  • pageX
  • pageY

Note that these measurements are not available until after the rendering has been completed in native. If you need the measurements as soon as possible, consider using the onLayout prop instead.

static measureInWindow(callback)

Determines the location of the given view in the window and returns the values via an async callback. If the React root view is embedded in another native view, this will give you the absolute coordinates. If successful, the callback will be called with the following arguments:

  • x
  • y
  • width
  • height

Note that these measurements are not available until after the rendering has been completed in native.

static measureLayout(relativeToNativeNode, onSuccess, onFail)

Like measure(), but measures the view relative an ancestor, specified as relativeToNativeNode. This means that the returned x, y are relative to the origin x, y of the ancestor view.

As always, to obtain a native node handle for a component, you can use ReactNative.findNodeHandle(component).

static focus()

Requests focus for the given input or view. The exact behavior triggered will depend on the platform and type of view.

static blur()

Removes focus from an input or view. This is the opposite of focus().

© 2015–2017 Facebook Inc.
Licensed under the Creative Commons Attribution 4.0 International Public License.
https://facebook.github.io/react-native/docs/nativemethodsmixin.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部