Sto tentando di avvolgere l'API Android di YouTube come componente dell'interfaccia utente per React Native. Ho avuto successo nella configurazione delle cose su Android (ottenendoInitializationSuccess), tuttavia non sono in grado di capire come riportare YouTubePlayerView alla mia app React Native.Esporre frammento in React Native Android ViewManager
In base ai documenti, è consigliabile utilizzare YouTubePlayerFragment se non è possibile estendere YouTubeBaseActivity. Poiché React Native su Android non utilizza layout basati su XML, ho tentato di creare le viste a livello di programmazione. Tuttavia, quando restituisco la vista di avvolgimento (ho provato come FrameLayout, ma non sono sicuro che quella fosse la scelta giusta), l'ho creata non rende nulla sull'applicazione.
Sto cercando di tenerlo estremamente semplice per ora, qui ci sono i bit necessari di codice:
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>
);
}
}
Qualsiasi aiuto sarebbe davvero apprezzato, grazie!
Fa regolazione in altezza e larghezza esplicita su youtube aiuto dei componenti? –
@agent_hunt sì, ho provato a dargli un'altezza/larghezza fissa e backgroundColor. Rende solo una vista vuota https: //www.dropbox.com/s/3obfjs6agcux3z2/Screenshot% 202016-03-26% 2017.10.55.png? dl = 0 – stan229
Il problema è risolto? Sei riuscito a rendere il frammento? – lschmierer