tôi cần phải sửa đổi một module đã lỗi thời (react-android-360-video) và thấy hữu ích ...
này Trong android/app/src/main/java/com/webcdpmobiledemo/MainApplication.java
, tôi sử dụng định dạng mới để thêm một gói:
...
import com.vrvideocomponent.VrVideoViewPackage;
public class MainApplication extends Application implements ReactApplication {
...
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
...
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new VrVideoViewPackage()
);
}
...
};
...
}
Và android/app/src/main/java/com/webcdpmobiledemo/MainActivity.java
là chủ yếu có sản phẩm nào:
package com.yourproject;
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "YourProject";
}
}
Sau đó, tôi sửa đổi các tập tin VrVideoViewPackage, mà cần phải vượt qua reactContext
đến VrVideoViewManager
nó gọi:
...
public class VrVideoViewPackage implements ReactPackage {
...
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Arrays.<ViewManager>asList(
new VrVideoViewManager(reactContext)
);
}
}
Và cuối cùng, trong VrVideoViewManager
hoạt động có thể được truy cập như vậy:
...
import android.app.Activity;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.bridge.ReactContext;
...
public class VrVideoViewManager extends SimpleViewManager<VrVideoView> {
...
public VrVideoViewManager(ReactContext reactContext) {
// Do not store mActivity, always getCurrentActivity when needed
Activity mActivity = mContext.getCurrentActivity();
}
@Override
protected VrVideoView createViewInstance(ThemedReactContext reactContext) {
// You can also activity from ThemedReactContext
Activity mActivity = reactContext.getCurrentActivity();
VrVideoView vrView = new VrVideoView(mActivity);
vrView.setEventListener(new ActivityEventListener(vrView));
vrView.pauseVideo();
return new VrVideoView(mActivity);
}
...
}
Nguồn
2017-06-26 18:55:02
Ví dụ liên quan đến giao tiếp giữa các thành phần gốc và Android. [Repo Link] (http://github.com/amalChandran/ReactNative_Android_integration) – amalBit