完整的错误消息:
” 'BambuserPlayer'没有propType用于本机类型String的本地prop'RCTImageView.loadingIndicator.src'
如果您没有更改此支柱,这通常意味着您的本机代码和JavaScript代码不同步。更新两者应该会使问题消失。 “
我正在尝试建立一个从React-native到Android中的视图的桥梁。我试图按照文档here中的说明操作,但它一直给我错误。尝试要求我的BambuserPlayer.js时发生错误:
'use strict';
import { PropTypes } from 'react';
import { requireNativeComponent, View } from 'react-native';
var iface = {
name: 'BambuserPlayer',
propTypes: {
resourceUri: PropTypes.string,
...View.propTypes // include the default view properties
},
};
module.exports = requireNativeComponent('RCTImageView', iface);
BambuserPlayer.java
public class BambuserPlayer extends View {
private String resourceURI;
private String applicationID;
private SurfaceViewWithAutoAR mSurfaceViewWithAutoAr;
private BroadcastPlayer.Observer mObserver;
private BroadcastPlayer mBroadcastPlayer;
public BambuserPlayer(Context context) {
super(context);
this.resourceURI = "sdfsdf8";
this.applicationID = "sdffsdsdfsdfA";
mSurfaceViewWithAutoAr = new SurfaceViewWithAutoAR(context);
mObserver = new BroadcastPlayer.Observer() {
@Override
public void onStateChange(PlayerState playerState) {
Log.i("Broadcast Observer", "playerstate has changed and is now " + playerState);
}
@Override
public void onBroadcastLoaded(boolean b, int i, int i1) {
Log.i("Broadcast Observer", "Video is now loaded. Live is " + b);
}
};
mBroadcastPlayer = new BroadcastPlayer(context, resourceURI, applicationID, mSurfaceViewWithAutoAr, mObserver);
}
public void setResourceURI(String resourceURI) {
this.resourceURI = resourceURI;
}
}
BambuserPlayerManager.java:
public class BambuserPlayerManager extends SimpleViewManager<BambuserPlayer> {
public static final String REACT_CLASS = "BambuserPlayer";
@Override
public String getName() {
return REACT_CLASS;
}
@Override
protected BambuserPlayer createViewInstance(ThemedReactContext reactContext) {
return new BambuserPlayer(reactContext);
}
@ReactProp(name = "src")
public void setResourceURI(BambuserPlayer view, @Nullable String resourceURI) {
view.setResourceURI(resourceURI);
}
}
MainApplication.java:
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new BambuserBroadcasterPackage()
);
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
的package.json:
{
"name": "Sidecourtnative",
"version": "6.9.0",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"firebase": "^3.6.1",
"lodash": "^4.17.2",
"react": "15.3.2",
"react-native": "0.37.0"
},
"jest": {
"preset": "jest-react-native"
},
"devDependencies": {
"babel-jest": "17.0.2",
"babel-preset-react-native": "1.9.0",
"flow-bin": "^0.35.0",
"jest": "17.0.2",
"jest-react-native": "17.0.2",
"react-test-renderer": "15.3.2",
"whatwg-fetch": "1.1.0"
}
}
我没有改变道具'RCTImageView.loadingIndicator.src': 我已经尝试更新到react-native 0.39,但这没有用,我尝试了运行npm start --reset-cache并重新安装所有节点模块。
非常感谢任何帮助!
答案 0 :(得分:1)
而不是
requireNativeComponent('RCTImageView', ...)
你想要
requireNativeComponent('BambuserPlayer', ...)