Skip to content

Commit

Permalink
feat(Android): Rounded Corners support for RTCSurfaceView
Browse files Browse the repository at this point in the history
  • Loading branch information
AB-70 authored Jun 11, 2024
1 parent 6b646e8 commit fd90ccf
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public String getName() {
@Override
public FrameLayout createViewInstance(ThemedReactContext context) {
this.context = context;
FrameLayout layout = new FrameLayout(context.getReactApplicationContext());
RoundedFrameLayout layout = new RoundedFrameLayout(context.getReactApplicationContext());
layout.addView(new SurfaceView(context.getApplicationContext()));
return layout;
}
Expand Down Expand Up @@ -55,4 +55,11 @@ public void setZOrderOnTop(FrameLayout view, boolean onTop) {
public void setZOrderMediaOverlay(FrameLayout view, boolean isMediaOverlay) {
((SurfaceView) view.getChildAt(0)).setZOrderMediaOverlay(isMediaOverlay);
}


@Override
@ReactProp(name = "cornerRadius")
public void setCornerRadius(FrameLayout view, float radius){
((RoundedFrameLayout) view).setCornerRadius(radius);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.agora.rtc.ng.react;

import android.view.SurfaceView;
import android.widget.FrameLayout;

import androidx.annotation.Nullable;

import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.annotations.ReactProp;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.util.AttributeSet;

public class RoundedFrameLayout extends FrameLayout {
private float cornerRadius = 18;

public RoundedFrameLayout(Context context) {
super(context);
}

public RoundedFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}

public RoundedFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@Override
protected void dispatchDraw(Canvas canvas) {
Path path = new Path();
float[] radii = {cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius};
path.addRoundRect(0, 0, getWidth(), getHeight(), radii, Path.Direction.CW);
canvas.clipPath(path);
super.dispatchDraw(canvas);
}

public void setCornerRadius(float radius) {
cornerRadius = radius;
invalidate();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ public abstract class AgoraRtcSurfaceViewManagerSpec<T extends View> extends Sim
public abstract void setZOrderOnTop(T view, boolean onTop);

public abstract void setZOrderMediaOverlay(T view, boolean isMediaOverlay);

public abstract void setCornerRadius(T view, float radius);

}
5 changes: 5 additions & 0 deletions src/AgoraRtcRenderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export interface RtcSurfaceViewProps extends RtcRendererViewProps {
* Controls whether to place the surface of the RtcSurfaceView on top of another RtcSurfaceView in the window (but still behind the window): true : Place it on top of another RtcSurfaceView in the window. false : Do not place it on top of another RtcSurfaceView in the window.
*/
zOrderMediaOverlay?: boolean;

/**
* Sets the corner radius of the SurfaceView's container.
*/
cornerRadius?: number;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/specs/AgoraRtcSurfaceViewNativeComponent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { HostComponent, ViewProps } from 'react-native';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
import { Float } from 'react-native/Libraries/Types/CodegenTypes';

export interface NativeProps extends ViewProps {
callApi: {
Expand All @@ -9,6 +10,7 @@ export interface NativeProps extends ViewProps {
};
zOrderOnTop?: boolean;
zOrderMediaOverlay?: boolean;
cornerRadius?: Float;
}

export default codegenNativeComponent<NativeProps>(
Expand Down

0 comments on commit fd90ccf

Please sign in to comment.