Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I import NativeMethodsMixin? #13330

Closed
evollu opened this issue Apr 5, 2017 · 5 comments
Closed

How do I import NativeMethodsMixin? #13330

evollu opened this issue Apr 5, 2017 · 5 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@evollu
Copy link

evollu commented Apr 5, 2017

I did import {NativeMethodsMixin} from 'react-native' but it is undefined.
here is exponent example. You will get redbox.
https://snack.expo.io/HJq_dCGTl

@hramos
Copy link
Contributor

hramos commented Apr 6, 2017

There's a couple of examples if you grep for NativeMethodsMixin in the code base. Both of these should work:

import NativeMethodsMixin from 'NativeMethodsMixin';
var NativeMethodsMixin = require('NativeMethodsMixin');

@hramos hramos closed this as completed Apr 6, 2017
@evollu
Copy link
Author

evollu commented Apr 6, 2017

I think this kind of import only work inside react native project (powered by haste?)
For the application everything should come from react-native module.
tried your suggestion and failed: https://snack.expo.io/SynGpBXax
@hramos

@johnwatsondev
Copy link

@evollu Yes. We cannot use it. :(

@evollu
Copy link
Author

evollu commented Aug 27, 2017

@hramos is it something react native can expose? Can you reopen this issue?

@johnwatsondev
Copy link

@evollu I have a tricky approach. We just use several methods of the object of NativeMethodsMixin.

const NativeMethodsMixin = {
  measure: function(callback) {
    UIManager.measure(findNumericNodeHandle(this), mountSafeCallback(this, callback));
  },
  measureInWindow: function(callback) {
    UIManager.measureInWindow(findNumericNodeHandle(this), mountSafeCallback(this, callback));
  },
  measureLayout: function(relativeToNativeNode, onSuccess, onFail) {
    UIManager.measureLayout(findNumericNodeHandle(this), relativeToNativeNode, mountSafeCallback(this, onFail), mountSafeCallback(this, onSuccess));
  },
  setNativeProps: function(nativeProps) {
    injectedSetNativeProps(this, nativeProps);
  },
  focus: function() {
    TextInputState.focusTextInput(findNumericNodeHandle(this));
  },
  blur: function() {
    TextInputState.blurTextInput(findNumericNodeHandle(this));
  }
};

I copy the dependency of NativeMethodsMixin to a single file.

nativemethodsmixin

So, I can use it anywhere.

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants