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

feat: implement opacity to control visibility of subtitles #3583

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ class SubtitleStyle private constructor() {
private set
var paddingBottom = 0
private set
var opacity = 1
private set

companion object {
private const val PROP_FONT_SIZE_TRACK = "fontSize"
private const val PROP_PADDING_BOTTOM = "paddingBottom"
private const val PROP_PADDING_TOP = "paddingTop"
private const val PROP_PADDING_LEFT = "paddingLeft"
private const val PROP_PADDING_RIGHT = "paddingRight"
private const val PROP_OPACITY = "opacity"

@JvmStatic
fun parse(src: ReadableMap?): SubtitleStyle {
Expand All @@ -33,6 +36,7 @@ class SubtitleStyle private constructor() {
subtitleStyle.paddingTop = ReactBridgeUtils.safeGetInt(src, PROP_PADDING_TOP, 0)
subtitleStyle.paddingLeft = ReactBridgeUtils.safeGetInt(src, PROP_PADDING_LEFT, 0)
subtitleStyle.paddingRight = ReactBridgeUtils.safeGetInt(src, PROP_PADDING_RIGHT, 0)
subtitleStyle.opacity = ReactBridgeUtils.safeGetInt(src, PROP_OPACITY, 1)
return subtitleStyle
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public void setSubtitleStyle(SubtitleStyle style) {
subtitleLayout.setFixedTextSize(TypedValue.COMPLEX_UNIT_SP, style.getFontSize());
}
subtitleLayout.setPadding(style.getPaddingLeft(), style.getPaddingTop(), style.getPaddingRight(), style.getPaddingBottom());
subtitleLayout.setVisibility(style.getOpacity() == 0 ? View.GONE : View.VISIBLE);
coofzilla marked this conversation as resolved.
Show resolved Hide resolved
}

public void setShutterColor(Integer color) {
Expand Down
2 changes: 2 additions & 0 deletions docs/pages/component/events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ Example:
}
```

For details on how to control the visibility of subtitles, see the [subtitleStyle](./props.mdx#subtitleStyle) section.

### `onVideoTracks`

<PlatformsList types={['Android']} />
Expand Down
3 changes: 2 additions & 1 deletion docs/pages/component/props.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -739,11 +739,12 @@ source={{
| paddingBottom | Adjust the bottom padding of the subtitles. Default: 0 | Android |
| paddingLeft | Adjust the left padding of the subtitles. Default: 0 | Android |
| paddingRight | Adjust the right padding of the subtitles. Default: 0 | Android |
| opacity | Adjust the visibility of subtitles. `0` will not render the subtitles, while `1` will make them fully visible. Default: 1. | Android |

Example:

```javascript
subtitleStyle={{ paddingBottom: 50, fontSize: 20 }}
subtitleStyle={{ paddingBottom: 50, fontSize: 20, opacity: 0 }}
```

### `textTracks`
Expand Down
1 change: 1 addition & 0 deletions src/specs/VideoNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type SubtitleStyle = Readonly<{
paddingBottom?: WithDefault<Float, 0>;
paddingLeft?: WithDefault<Float, 0>;
paddingRight?: WithDefault<Float, 0>;
opacity?: WithDefault<0 | 1, 1>;
}>;

export type OnLoadData = Readonly<{
Expand Down
1 change: 1 addition & 0 deletions src/types/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export type SubtitleStyle = {
paddingBottom?: number;
paddingLeft?: number;
paddingRight?: number;
opacity?: 0 | 1;
};

export enum TextTracksType {
Expand Down
Loading