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

fix(android): add custom display metrics #3965

Merged
merged 2 commits into from
Jul 24, 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 @@ -173,7 +173,7 @@ public static HippyMap getDimensions(int ww, int wh, Context context) {
if (context == null) {
return null;
}
DisplayMetrics windowDisplayMetrics = PixelUtil.getMetrics();
DisplayMetrics windowDisplayMetrics = PixelUtil.getCustomDisplayMetrics();
if (windowDisplayMetrics == null) {
windowDisplayMetrics = context.getResources().getDisplayMetrics();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@
import android.util.TypedValue;
import android.view.Display;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class PixelUtil {

private static DisplayMetrics sDisplayMetrics = null;
private static DisplayMetrics sCustomDisplayMetrics = null;

public static DisplayMetrics getMetrics() {
if (sCustomDisplayMetrics != null) {
return sCustomDisplayMetrics;
}
if (sDisplayMetrics == null) {
sDisplayMetrics = new DisplayMetrics();
WindowManager windowManager = (WindowManager) ContextHolder.getAppContext()
Expand All @@ -37,12 +43,17 @@ public static DisplayMetrics getMetrics() {
return sDisplayMetrics;
}

@Nullable
public static DisplayMetrics getCustomDisplayMetrics() {
return sCustomDisplayMetrics;
}

/**
* Set display metrics, call by host app
*/
@SuppressWarnings("unused")
public static void setDisplayMetrics(DisplayMetrics metrics) {
sDisplayMetrics = metrics;
public static void setDisplayMetrics(@NonNull DisplayMetrics metrics) {
sCustomDisplayMetrics = metrics;
}

/**
Expand Down
Loading