Skip to content

Commit

Permalink
feat: add ability to have range of numbers for opacity; while, 0 will…
Browse files Browse the repository at this point in the history
… still not render the subtitles.

added util function for safeGetFloat

updated types
  • Loading branch information
coofzilla committed Mar 12, 2024
1 parent b9d6f04 commit dfe8bfd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SubtitleStyle private constructor() {
private set
var paddingBottom = 0
private set
var opacity = 1
var opacity = 1f
private set

companion object {
Expand All @@ -36,7 +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)
subtitleStyle.opacity = ReactBridgeUtils.safeGetFloat(src, PROP_OPACITY, 1f)
return subtitleStyle
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ object ReactBridgeUtils {
return safeGetDouble(map, key, 0.0)
}

@JvmStatic fun safeGetFloat(map: ReadableMap?, key: String?, fallback: Float): Float {
return if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getDouble(key).toFloat() else fallback
}

@JvmStatic fun safeGetFloat(map: ReadableMap?, key: String?): Float {
return safeGetFloat(map, key, 0.0f)
}

/**
* toStringMap converts a [ReadableMap] into a HashMap.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ 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);
if (style.getOpacity() != 0) {
subtitleLayout.setAlpha(style.getOpacity());
} else {
subtitleLayout.setVisibility(View.GONE);
}

}

public void setShutterColor(Integer color) {
Expand Down
2 changes: 1 addition & 1 deletion src/specs/VideoNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ type SubtitleStyle = Readonly<{
paddingBottom?: WithDefault<Float, 0>;
paddingLeft?: WithDefault<Float, 0>;
paddingRight?: WithDefault<Float, 0>;
opacity?: WithDefault<0 | 1, 1>;
opacity?: WithDefault<Float, 1>;
}>;

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

export enum TextTracksType {
Expand Down

0 comments on commit dfe8bfd

Please sign in to comment.