-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support default font options (#6613)
This PR continues the work done in #6590 and adds support for declaring `fontWeight` and `fontFamily` for title and subtitle in default options.
- Loading branch information
Showing
25 changed files
with
215 additions
and
145 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
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
55 changes: 55 additions & 0 deletions
55
lib/android/app/src/main/java/com/reactnativenavigation/options/FontOptions.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,55 @@ | ||
package com.reactnativenavigation.options | ||
|
||
import android.graphics.Typeface | ||
import com.reactnativenavigation.options.params.NullText | ||
import com.reactnativenavigation.options.params.Text | ||
import com.reactnativenavigation.options.parsers.TypefaceLoader | ||
|
||
class FontOptions { | ||
private var isDirty = false | ||
var fontFamily: Text = NullText() | ||
set(value) { | ||
field = value | ||
isDirty = true | ||
} | ||
var fontStyle: Text = NullText() | ||
set(value) { | ||
field = value | ||
isDirty = true | ||
} | ||
var fontWeight: Text = NullText() | ||
set(value) { | ||
field = value | ||
isDirty = true | ||
} | ||
private var _typeface: Typeface? = null | ||
|
||
@JvmOverloads fun getTypeface(typefaceLoader: TypefaceLoader, defaultTypeface: Typeface? = null): Typeface? { | ||
if (isDirty) { | ||
_typeface = typefaceLoader.getTypeFace(fontFamily.get(""), fontStyle.get(""), fontWeight.get("")) | ||
isDirty = false | ||
} | ||
return _typeface | ||
?: defaultTypeface?.let { typefaceLoader.getTypeFace(fontFamily.get(""), fontStyle.get(""), fontWeight.get(""), it) } | ||
} | ||
|
||
fun mergeWith(other: FontOptions) { | ||
if (other.fontFamily.hasValue()) fontFamily = other.fontFamily | ||
if (other.fontStyle.hasValue()) fontStyle = other.fontStyle | ||
if (other.fontWeight.hasValue()) fontWeight = other.fontWeight | ||
} | ||
|
||
fun mergeWithDefault(defaultOptions: FontOptions) { | ||
if (!fontFamily.hasValue()) fontFamily = defaultOptions.fontFamily | ||
if (!fontStyle.hasValue()) fontStyle = defaultOptions.fontStyle | ||
if (!fontWeight.hasValue()) fontWeight = defaultOptions.fontWeight | ||
} | ||
|
||
fun hasValue() = fontFamily.hasValue() || fontStyle.hasValue() || fontWeight.hasValue() | ||
|
||
override fun equals(other: Any?) = (other as? FontOptions)?.let { | ||
fontFamily.equals(other.fontFamily) && | ||
fontStyle.equals(other.fontStyle) && | ||
fontWeight.equals(other.fontWeight) | ||
} ?: false | ||
} |
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
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
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
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
Oops, something went wrong.