我正在使用本机Android ProgressBar
来响应本机,但是出了点问题。这是我的ProgressBarViewManager
代码:
public class ProgressBarViewManager extends
SimpleViewManager<ProgressBar> {
public static final String REACT_CLASS = "ProgressBar";
@Override
public String getName() {
return REACT_CLASS;
}
@Override
protected ProgressBar createViewInstance(ThemedReactContext reactContext) {
return new ProgressBar(reactContext);
}
@ReactProp(name = "progress", defaultInt = 0)
public void setProgress(ProgressBar view, int progress) {
view.setProgress(progress);
}
@ReactProp(name = "indeterminate", defaultBoolean = false)
public void setIndeterminate(ProgressBar view, boolean indeterminate) {
view.setIndeterminate(indeterminate);
}
}
这是我的ProgressBarPackage代码
public class ProgressBarPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.<ViewManager>singletonList(
new ProgressBarViewManager()
);
}
}
我还在MainApplication.java
中添加了 new ProgressBarPackage(),但运行后却出现错误:
**Task :app:compileDebugJavaWithJavac FAILED
/home/user/React-native-Projects/AndroidComponentIntegeration/android/app/src/main/java/com/androidcomponentintegeration/ProgressBarPackage.java:19: error: method does not override or implement a method from a supertype
@Override**
答案 0 :(得分:1)
只需从ProgressBarPackage.java中的line19方法中删除@override
批注。对于其他方法,应该再次出现pops错误。如果其他方法弹出错误,则还需要从所有这些方法中删除@override
答案 1 :(得分:1)
ProgressBarPackage不扩展超类;因此,它不能覆盖方法。如果删除注释,则可能会起作用。
答案 2 :(得分:1)
ReactPackage类不再(从this change起,包含在React Native 0.47中)定义了一个createJSModules
方法,因此您不再需要提供它的实现。只需删除该方法(包括其@Override注释):
public class ProgressBarPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.<ViewManager>singletonList(
new ProgressBarViewManager()
);
}
}