@volcengine/react-native-live-push 1.0.3-rc.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,34 +1,113 @@
1
1
  package com.volcengine.velive.rn.push;
2
2
 
3
- import android.content.Context;
3
+ import android.graphics.SurfaceTexture;
4
4
  import android.util.Log;
5
+ import android.view.SurfaceHolder;
5
6
  import android.view.SurfaceView;
7
+ import android.view.TextureView;
6
8
  import android.view.View;
7
9
  import android.widget.FrameLayout;
8
-
10
+ import androidx.annotation.NonNull;
9
11
  import com.facebook.react.bridge.Arguments;
10
12
  import com.facebook.react.bridge.ReactContext;
11
13
  import com.facebook.react.bridge.WritableMap;
14
+ import com.facebook.react.uimanager.ThemedReactContext;
12
15
  import com.facebook.react.uimanager.events.RCTEventEmitter;
16
+ import com.volcengine.VolcApiEngine.view.VolcViewManager;
13
17
 
14
18
  public class VeLivePushView extends FrameLayout {
15
19
  public String viewId;
20
+ public String viewKind;
16
21
  public boolean hasRegister = false;
17
-
18
- public VeLivePushView(Context context) {
22
+ private final ThemedReactContext themedReactContext;
23
+ private boolean hasLoad = false;
24
+ private View subview;
25
+
26
+ public VeLivePushView(ThemedReactContext context) {
19
27
  super(context);
28
+ this.themedReactContext = context;
20
29
  }
21
-
30
+
22
31
  public void setViewId(String viewId) {
23
- this.viewId = viewId;
32
+ this.viewId = viewId;
24
33
  this.hasRegister = true;
25
- this.emitOnLoad();
26
34
  }
27
-
35
+
36
+ public void setViewKind(String viewKind) {
37
+ this.viewKind = viewKind;
38
+ switch (viewKind) {
39
+ case "SurfaceView":
40
+ SurfaceView surfaceView =
41
+ new SurfaceView(themedReactContext.getReactApplicationContext());
42
+ surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
43
+ @Override
44
+ public void surfaceCreated(@NonNull SurfaceHolder holder) {
45
+ subview = surfaceView;
46
+ VolcViewManager.putViewById(viewId, subview);
47
+ emitOnLoad();
48
+ hasLoad = true;
49
+ }
50
+
51
+ @Override
52
+ public void surfaceChanged(@NonNull SurfaceHolder holder, int format,
53
+ int width, int height) {}
54
+
55
+ @Override
56
+ public void surfaceDestroyed(@NonNull SurfaceHolder holder) {}
57
+ });
58
+ this.addView(surfaceView);
59
+ break;
60
+ case "TextureView":
61
+ TextureView textureView =
62
+ new TextureView(themedReactContext.getReactApplicationContext());
63
+ subview = textureView;
64
+ textureView.setSurfaceTextureListener(
65
+ new TextureView.SurfaceTextureListener() {
66
+ @Override
67
+ public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture,
68
+ int width, int height) {
69
+ VolcViewManager.putViewById(viewId, subview);
70
+ emitOnLoad();
71
+ hasLoad = true;
72
+ }
73
+ @Override
74
+ public void onSurfaceTextureSizeChanged(
75
+ SurfaceTexture surfaceTexture, int width, int height) {}
76
+ @Override
77
+ public boolean onSurfaceTextureDestroyed(
78
+ SurfaceTexture surfaceTexture) {
79
+ return true;
80
+ }
81
+ @Override
82
+ public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
83
+ }
84
+ });
85
+ this.addView(textureView);
86
+ break;
87
+ default:
88
+ break;
89
+ }
90
+ }
91
+
92
+ public void resetSurface() {
93
+ if (subview instanceof SurfaceView) {
94
+ SurfaceView surface = (SurfaceView)subview;
95
+ post(new Runnable() {
96
+ @Override
97
+ public void run() {
98
+ removeView(surface);
99
+ addView(surface);
100
+ surface.requestLayout();
101
+ surface.invalidate();
102
+ }
103
+ });
104
+ }
105
+ }
106
+
28
107
  public void setVisible(Boolean visible) {
29
108
  Log.i("surfaceView", "setVisible");
30
109
  View subview = this.getChildAt(0);
31
- if(visible) {
110
+ if (visible) {
32
111
  subview.setVisibility(View.VISIBLE);
33
112
  } else {
34
113
  subview.setVisibility(View.INVISIBLE);
@@ -36,10 +115,12 @@ public class VeLivePushView extends FrameLayout {
36
115
  }
37
116
 
38
117
  public void emitOnLoad() {
118
+ if (hasLoad) {
119
+ return;
120
+ }
39
121
  WritableMap event = Arguments.createMap();
40
122
  ReactContext reactContext = (ReactContext)getContext();
41
- reactContext
42
- .getJSModule(RCTEventEmitter.class)
43
- .receiveEvent(getId(), "load", event);
123
+ reactContext.getJSModule(RCTEventEmitter.class)
124
+ .receiveEvent(getId(), "load", event);
44
125
  }
45
126
  }
@@ -1,26 +1,20 @@
1
1
  package com.volcengine.velive.rn.push;
2
2
 
3
3
  import android.os.Looper;
4
- import android.view.SurfaceView;
5
- import android.view.View;
6
-
7
4
  import androidx.annotation.NonNull;
8
5
  import androidx.annotation.Nullable;
9
-
10
6
  import com.facebook.react.bridge.ReadableArray;
11
7
  import com.facebook.react.common.MapBuilder;
12
8
  import com.facebook.react.uimanager.SimpleViewManager;
13
9
  import com.facebook.react.uimanager.ThemedReactContext;
14
10
  import com.facebook.react.uimanager.annotations.ReactProp;
15
- import com.volcengine.VolcApiEngine.view.*;
16
-
17
11
  import java.util.Map;
18
12
 
19
13
  public class VeLivePushViewManager extends SimpleViewManager<VeLivePushView> {
20
14
  public static final String NAME = "VeLivePushView";
21
-
22
- private ThemedReactContext context;
23
15
 
16
+ private ThemedReactContext context;
17
+
24
18
  @NonNull
25
19
  @Override
26
20
  public String getName() {
@@ -29,64 +23,54 @@ public class VeLivePushViewManager extends SimpleViewManager<VeLivePushView> {
29
23
 
30
24
  @NonNull
31
25
  @Override
32
- protected VeLivePushView createViewInstance(@NonNull ThemedReactContext reactContext) {
26
+ protected VeLivePushView
27
+ createViewInstance(@NonNull ThemedReactContext reactContext) {
33
28
  // 确保在主线程创建
34
29
  if (Looper.myLooper() != Looper.getMainLooper()) {
35
- throw new IllegalStateException("View must be created on the main thread");
30
+ throw new IllegalStateException(
31
+ "View must be created on the main thread");
36
32
  }
37
33
  context = reactContext;
38
34
  return new VeLivePushView(reactContext);
39
35
  }
40
-
36
+
41
37
  @ReactProp(name = "viewId")
42
38
  public void setViewId(VeLivePushView view, String viewId) {
43
39
  view.setViewId(viewId);
44
- VolcViewManager.putViewById(viewId, view);
45
40
  }
46
41
 
47
42
  @ReactProp(name = "kind")
48
43
  public void setKind(VeLivePushView view, String kind) {
49
- var themedReactContext = this.context;
50
-
51
- switch (kind) {
52
- case "SurfaceView" -> {
53
- SurfaceView subView = new SurfaceView(themedReactContext.getReactApplicationContext());
54
- view.addView(subView);
55
- }
56
- case "View" -> {
57
- View subView = new View(themedReactContext.getApplicationContext());
58
- view.addView(subView);
59
- }
60
- }
44
+ view.setViewKind(kind);
61
45
  }
62
-
46
+
63
47
  public void setVisible(VeLivePushView view, Boolean visible) {
64
48
  view.setVisible(visible);
65
49
  }
50
+
51
+ public void resetSurface(VeLivePushView view) {
52
+ view.resetSurface();
53
+ }
66
54
 
67
55
  /**
68
56
  * Handle "create" command (called from JS) and call createFragment method
69
57
  */
70
- public void receiveCommand(
71
- @NonNull VeLivePushView root,
72
- String command,
73
- @Nullable ReadableArray args
74
- ) {
58
+ public void receiveCommand(@NonNull VeLivePushView root, String command,
59
+ @Nullable ReadableArray args) {
75
60
  super.receiveCommand(root, command, args);
76
-
61
+
77
62
  if (command.equals("setVisible")) {
78
63
  assert args != null;
79
64
  setVisible(root, args.getBoolean(0));
65
+ } else if(command.equals("resetSurface")) {
66
+ resetSurface(root);
80
67
  }
81
68
  }
82
69
 
83
70
  public Map getExportedCustomBubblingEventTypeConstants() {
84
- return MapBuilder.builder().put(
85
- "load",
86
- MapBuilder.of(
87
- "phasedRegistrationNames",
88
- MapBuilder.of("bubbled", "onViewLoad")
89
- )
90
- ).build();
71
+ return MapBuilder.builder()
72
+ .put("load", MapBuilder.of("phasedRegistrationNames",
73
+ MapBuilder.of("bubbled", "onViewLoad")))
74
+ .build();
91
75
  }
92
76
  }