mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-28 12:15:37 +08:00
Fix ART surface sleep issue
Summary: Fixes https://github.com/facebook/react-native/issues/17565. Reviewed By: achen1 Differential Revision: D8194925 fbshipit-source-id: 5448d49d959078eaded697f791e1b382471fabdb
This commit is contained in:
committed by
Facebook Github Bot
parent
5863b564f8
commit
5fc42f308a
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
package com.facebook.react.flat;
|
package com.facebook.react.flat;
|
||||||
|
|
||||||
|
import android.view.SurfaceHolder;
|
||||||
import com.facebook.react.uimanager.BaseViewManager;
|
import com.facebook.react.uimanager.BaseViewManager;
|
||||||
import com.facebook.react.uimanager.ThemedReactContext;
|
import com.facebook.react.uimanager.ThemedReactContext;
|
||||||
import com.facebook.react.views.art.ARTSurfaceView;
|
import com.facebook.react.views.art.ARTSurfaceView;
|
||||||
@@ -14,6 +15,7 @@ import com.facebook.yoga.YogaMeasureFunction;
|
|||||||
import com.facebook.yoga.YogaMeasureMode;
|
import com.facebook.yoga.YogaMeasureMode;
|
||||||
import com.facebook.yoga.YogaNode;
|
import com.facebook.yoga.YogaNode;
|
||||||
|
|
||||||
|
|
||||||
public class FlatARTSurfaceViewManager extends
|
public class FlatARTSurfaceViewManager extends
|
||||||
BaseViewManager<ARTSurfaceView, FlatARTSurfaceViewShadowNode> {
|
BaseViewManager<ARTSurfaceView, FlatARTSurfaceViewShadowNode> {
|
||||||
|
|
||||||
@@ -55,6 +57,6 @@ public class FlatARTSurfaceViewManager extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateExtraData(ARTSurfaceView root, Object extraData) {
|
public void updateExtraData(ARTSurfaceView root, Object extraData) {
|
||||||
root.setSurfaceTextureListener((FlatARTSurfaceViewShadowNode) extraData);
|
root.getHolder().addCallback((FlatARTSurfaceViewShadowNode) extraData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import android.graphics.PorterDuff;
|
|||||||
import android.graphics.SurfaceTexture;
|
import android.graphics.SurfaceTexture;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import android.view.TextureView;
|
import android.view.SurfaceHolder;
|
||||||
|
|
||||||
import com.facebook.react.common.ReactConstants;
|
import com.facebook.react.common.ReactConstants;
|
||||||
import com.facebook.react.uimanager.ReactShadowNode;
|
import com.facebook.react.uimanager.ReactShadowNode;
|
||||||
@@ -25,8 +25,9 @@ import com.facebook.react.views.art.ARTVirtualNode;
|
|||||||
import com.facebook.yoga.YogaValue;
|
import com.facebook.yoga.YogaValue;
|
||||||
import com.facebook.yoga.YogaUnit;
|
import com.facebook.yoga.YogaUnit;
|
||||||
|
|
||||||
|
|
||||||
/* package */ class FlatARTSurfaceViewShadowNode extends FlatShadowNode
|
/* package */ class FlatARTSurfaceViewShadowNode extends FlatShadowNode
|
||||||
implements AndroidView, TextureView.SurfaceTextureListener {
|
implements AndroidView, SurfaceHolder.Callback {
|
||||||
private boolean mPaddingChanged = false;
|
private boolean mPaddingChanged = false;
|
||||||
private @Nullable Surface mSurface;
|
private @Nullable Surface mSurface;
|
||||||
|
|
||||||
@@ -123,21 +124,16 @@ import com.facebook.yoga.YogaUnit;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
|
public void surfaceCreated(SurfaceHolder holder) {
|
||||||
mSurface = new Surface(surface);
|
mSurface = holder.getSurface();
|
||||||
drawOutput();
|
drawOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
|
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||||
surface.release();
|
|
||||||
mSurface = null;
|
mSurface = null;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {}
|
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSurfaceTextureUpdated(SurfaceTexture surface) {}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,13 @@
|
|||||||
package com.facebook.react.views.art;
|
package com.facebook.react.views.art;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.TextureView;
|
import android.view.SurfaceView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom {@link View} implementation that draws an ARTSurface React view and its children.
|
* Custom {@link View} implementation that draws an ARTSurface React view and its children.
|
||||||
*/
|
*/
|
||||||
public class ARTSurfaceView extends TextureView {
|
public class ARTSurfaceView extends SurfaceView {
|
||||||
public ARTSurfaceView(Context context) {
|
public ARTSurfaceView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
setOpaque(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
package com.facebook.react.views.art;
|
package com.facebook.react.views.art;
|
||||||
|
|
||||||
|
import android.view.SurfaceHolder;
|
||||||
import com.facebook.yoga.YogaMeasureMode;
|
import com.facebook.yoga.YogaMeasureMode;
|
||||||
import com.facebook.yoga.YogaMeasureFunction;
|
import com.facebook.yoga.YogaMeasureFunction;
|
||||||
import com.facebook.yoga.YogaNode;
|
import com.facebook.yoga.YogaNode;
|
||||||
@@ -60,7 +61,7 @@ public class ARTSurfaceViewManager extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateExtraData(ARTSurfaceView root, Object extraData) {
|
public void updateExtraData(ARTSurfaceView root, Object extraData) {
|
||||||
root.setSurfaceTextureListener((ARTSurfaceViewShadowNode) extraData);
|
root.getHolder().addCallback((ARTSurfaceViewShadowNode) extraData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -15,8 +15,10 @@ import android.graphics.Color;
|
|||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.SurfaceTexture;
|
import android.graphics.SurfaceTexture;
|
||||||
|
import android.view.SurfaceHolder;
|
||||||
import android.view.TextureView;
|
import android.view.TextureView;
|
||||||
|
|
||||||
|
|
||||||
import com.facebook.common.logging.FLog;
|
import com.facebook.common.logging.FLog;
|
||||||
import com.facebook.react.common.ReactConstants;
|
import com.facebook.react.common.ReactConstants;
|
||||||
import com.facebook.react.uimanager.LayoutShadowNode;
|
import com.facebook.react.uimanager.LayoutShadowNode;
|
||||||
@@ -29,7 +31,7 @@ import com.facebook.react.uimanager.annotations.ReactProp;
|
|||||||
* Shadow node for ART virtual tree root - ARTSurfaceView
|
* Shadow node for ART virtual tree root - ARTSurfaceView
|
||||||
*/
|
*/
|
||||||
public class ARTSurfaceViewShadowNode extends LayoutShadowNode
|
public class ARTSurfaceViewShadowNode extends LayoutShadowNode
|
||||||
implements TextureView.SurfaceTextureListener {
|
implements SurfaceHolder.Callback {
|
||||||
|
|
||||||
private @Nullable Surface mSurface;
|
private @Nullable Surface mSurface;
|
||||||
|
|
||||||
@@ -97,21 +99,17 @@ public class ARTSurfaceViewShadowNode extends LayoutShadowNode
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
|
public void surfaceCreated(SurfaceHolder holder) {
|
||||||
mSurface = new Surface(surface);
|
mSurface = holder.getSurface();
|
||||||
drawOutput();
|
drawOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
|
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||||
surface.release();
|
|
||||||
mSurface = null;
|
mSurface = null;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {}
|
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSurfaceTextureUpdated(SurfaceTexture surface) {}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user