-1

i'm trying to implement my first react native UI component, i followed the Facebook tutorial and it should be easy but i have some strange problem

public class CameraViewManager extends SimpleViewManager<CameraPreview> {

    public static final String REACT_CLASS = "RCTCameraView";

    @Override
    public String getName() {
         return REACT_CLASS;
    }

    @Override
    public CameraPreview createViewInstance(ThemedReactContext context) {
        return new CameraPreview(context);
    }

    @ReactProp(name = "test")
    public void setTest(CameraPreview view, @Nullable String test){
        Log.i("TESTWD", test);
    }

}

This is the ViewManager i'm using and to me it seems correct. The first problem is that android studio doesn't find @ReactProp and it doesn't compile. The second problem is that if i remove that method everything compile but when i use this component nothing appears

WellDone2094
  • 175
  • 1
  • 9
  • 3
    You need to `import com.facebook.react.uimanager.annotations.ReactProp;` instead of `import com.facebook.react.uimanager.ReactProp;` – if-else-switch May 18 '16 at 13:07

2 Answers2

5

Just ran into this myself. The solution is as if-else-switch pointed out in a comment above:

// Import this
import com.facebook.react.uimanager.annotations.ReactProp;

// Not this!
import com.facebook.react.uimanager.ReactProp;

There seem to be two @ReactProp definitions in different packages and Android Studio chooses the wrong one by default.

Community
  • 1
  • 1
SteveMellross
  • 3,404
  • 2
  • 20
  • 18
1

I solved this problem using react-native 0.13.+ instead of 0.11.+

WellDone2094
  • 175
  • 1
  • 9