React Native Android Native UI 组件找不到@ReactProps

Wel*_*094 -1 android facebook react-native react-native-camera

我正在尝试实现我的第一个 React Native UI 组件,我遵循了 Facebook 教程,这应该很容易,但我遇到了一些奇怪的问题

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);
    }

}
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的 ViewManager,对我来说似乎是正确的。第一个问题是android studio 找不到@ReactProp 并且无法编译。第二个问题是,如果我删除该方法,一切都会编译,但是当我使用这个组件时,什么都没有出现

Ste*_*oss 5

我自己就遇到了这个。解决方案就像if-else-switch在上面的评论中指出的那样:

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

// Not this!
import com.facebook.react.uimanager.ReactProp;
Run Code Online (Sandbox Code Playgroud)

@ReactProp在不同的包中似乎有两个定义,Android Studio 默认选择了错误的一个。