forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert DefaultStyleValuesUtil to Kotlin (facebook#43884)
Summary: Pull Request resolved: facebook#43884 convert Java to Kotlin: `/react/view/text/DefaultStyleValuesUtil.java` Changelog: [Internal] internal Differential Revision: D55777322
- Loading branch information
1 parent
ce0f83c
commit 6688d38
Showing
3 changed files
with
57 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
...tive/ReactAndroid/src/main/java/com/facebook/react/views/text/DefaultStyleValuesUtil.java
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
...native/ReactAndroid/src/main/java/com/facebook/react/views/text/DefaultStyleValuesUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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.R | ||
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, 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, 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, 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) | ||
} | ||
} | ||
} |