I am attempting to wrap the YouTube Android API as a UI Component for React Native. I have been successful in the Android configuration of things (getting onInitializationSuccess), however I am unable to figure out how get the YouTubePlayerView back to my React Native app.
According to the docs, they recommend using YouTubePlayerFragment if you can not extend YouTubeBaseActivity. Since React Native on Android does not use XML based layouts I attempted to create the views programmatically. However, when I return the wrapping View ( I tried as a FrameLayout, but not sure if that was the right choice) I created it does not render anything on the application.
I am looking to keep it extremely simple for now, here are the necessary bits of code:
YouTubeManager.java
public class YouTubeManager extends SimpleViewManager<FrameLayout> implements YouTubePlayer.OnInitializedListener {
// ...
@Override
protected FrameLayout createViewInstance(ThemedReactContext reactContext) {
this.reactContext = reactContext;
FrameLayout view = new FrameLayout(reactContext);
view.setId(View.generateViewId());
FragmentManager fragmentManager = activity.getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
YouTubePlayerFragment fragment = new YouTubePlayerFragment();
fragmentTransaction.add(view.getId(), fragment);
fragmentTransaction.commit();
fragment.initialize("SECRET_KEY", this);
return view;
}
// ...
}
YouTube.js
class YouTube extends Component {
render () {
return <YouTubeAndroid {...this.props}/>;
}
};
var iface = {
name : 'YouTube',
propTypes : {
...View.propTypes
},
};
var YouTubeAndroid = requireNativeComponent('YouTube', iface);
module.exports = YouTube;
index.android.js
var YouTube = require('./YouTube');
class YouTubePlayer extends Component {
render() {
return (
<View style={styles.container}>
<Text>hello</Text>
<YouTube />
</View>
);
}
}
Any help would be really appreciated, thank you!