Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#782 - Rounded Corners support for RTCSurfaceView #783

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
* 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;

Check failure on line 37 in src/AgoraRtcRenderView.tsx

View workflow job for this annotation

GitHub Actions / lint (ubuntu)

Delete `··`
/**
* Sets the corner radius of the SurfaceView's container.

Check failure on line 39 in src/AgoraRtcRenderView.tsx

View workflow job for this annotation

GitHub Actions / lint (ubuntu)

Delete `·`
*/
cornerRadius?: number;

Check failure on line 41 in src/AgoraRtcRenderView.tsx

View workflow job for this annotation

GitHub Actions / lint (ubuntu)

Delete `·`
}

/**
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';

Check failure on line 3 in src/specs/AgoraRtcSurfaceViewNativeComponent.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu)

`react-native/Libraries/Types/CodegenTypes` import should occur before import of `react-native/Libraries/Utilities/codegenNativeComponent`

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

export default codegenNativeComponent<NativeProps>(
Expand Down
Loading