Skip to content

Commit

Permalink
convert DefaultStyleValuesUtil to Kotlin (#43884)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #43884

convert Java to Kotlin: `/react/view/text/DefaultStyleValuesUtil.java`

Changelog:
[Internal] internal

Reviewed By: cortinico

Differential Revision: D55777322
  • Loading branch information
alanleedev authored and facebook-github-bot committed Apr 8, 2024
1 parent 7165bd3 commit 7bcf557
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 80 deletions.
7 changes: 4 additions & 3 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -6928,9 +6928,10 @@ public class com/facebook/react/views/switchview/ReactSwitchManager$ReactSwitchS
}

public final class com/facebook/react/views/text/DefaultStyleValuesUtil {
public static fun getDefaultTextColor (Landroid/content/Context;)Landroid/content/res/ColorStateList;
public static fun getDefaultTextColorHighlight (Landroid/content/Context;)I
public static fun getDefaultTextColorHint (Landroid/content/Context;)Landroid/content/res/ColorStateList;
public static final field INSTANCE Lcom/facebook/react/views/text/DefaultStyleValuesUtil;
public static final fun getDefaultTextColor (Landroid/content/Context;)Landroid/content/res/ColorStateList;
public static final fun getDefaultTextColorHighlight (Landroid/content/Context;)I
public static final fun getDefaultTextColorHint (Landroid/content/Context;)Landroid/content/res/ColorStateList;
}

public class com/facebook/react/views/text/FontMetricsUtil {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.views.text

import android.content.Context
import android.content.res.ColorStateList

/** Utility class that access default values from style */
public object DefaultStyleValuesUtil {

/**
* Utility method that returns the default text hint color as define by the theme
*
* @param context The Context
* @return The ColorStateList for the hint text as defined in the style
*/
@JvmStatic
public fun getDefaultTextColorHint(context: Context): ColorStateList? =
getDefaultTextAttribute(context, android.R.attr.textColorHint)

/**
* Utility method that returns the default text color as define by the theme
*
* @param context The Context
* @return The ColorStateList for the text as defined in the style
*/
@JvmStatic
public fun getDefaultTextColor(context: Context): ColorStateList? =
getDefaultTextAttribute(context, android.R.attr.textColor)

/**
* Utility method that returns the default text highlight color as define by the theme
*
* @param context The Context
* @return The int for the highlight color as defined in the style
*/
@JvmStatic
public fun getDefaultTextColorHighlight(context: Context): Int =
getDefaultTextAttribute(context, android.R.attr.textColorHighlight)?.defaultColor
?: 0 // if the highlight color is not defined in the theme, return black

private fun getDefaultTextAttribute(context: Context, attribute: Int): ColorStateList? {
context.theme.obtainStyledAttributes(intArrayOf(attribute)).use { typedArray ->
return typedArray.getColorStateList(0)
}
}
}

0 comments on commit 7bcf557

Please sign in to comment.