Skip to content

Commit

Permalink
Dynamic type flag works for all content size category changes (icons …
Browse files Browse the repository at this point in the history
…as well)
  • Loading branch information
byerlyb20 committed Jun 4, 2024
1 parent 8a20501 commit 7ad6c1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import platform.Foundation.NSOperationQueue
actual class NIconView(): NView(CGRectMake(0.0,0.0,0.0,0.0)), UIViewWithSpacingRulesProtocol {
init {
setUserInteractionEnabled(false)
NSNotificationCenter.defaultCenter.addObserverForName(UIContentSizeCategoryDidChangeNotification, null, NSOperationQueue.mainQueue) {
informParentOfSizeChange()
if (ENABLE_DYNAMIC_TYPE) {
NSNotificationCenter.defaultCenter.addObserverForName(UIContentSizeCategoryDidChangeNotification, null, NSOperationQueue.mainQueue) {
informParentOfSizeChange()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,11 @@ private val dynamicTypeScaleFactors = mapOf(
UIContentSizeCategoryExtraExtraExtraLarge to 1.42,
)
const val ENABLE_DYNAMIC_TYPE = false
fun preferredScaleFactor() = dynamicTypeScaleFactors[UIApplication.sharedApplication.preferredContentSizeCategory] ?: 1.0
fun preferredScaleFactor() = if (ENABLE_DYNAMIC_TYPE) {
dynamicTypeScaleFactors[UIApplication.sharedApplication.preferredContentSizeCategory] ?: 1.0
} else {
1.0
}
fun UILabelWithGradient.setContentSizeCategoryChangeListener() {
if (ENABLE_DYNAMIC_TYPE) {
NSNotificationCenter.defaultCenter.addObserverForName(UIContentSizeCategoryDidChangeNotification, null, NSOperationQueue.mainQueue) {
Expand All @@ -260,13 +264,7 @@ fun UILabelWithGradient.updateFont() = label.run {
val textSize = extensionTextSize ?: return
val alignment = textAlignment
font = extensionFontAndStyle?.let {
it.font.get(textSize.value.let {
if (ENABLE_DYNAMIC_TYPE) {
it * preferredScaleFactor()
} else {
it
}
}, it.weight.toUIFontWeight(), it.italic)
it.font.get(textSize.value * preferredScaleFactor(), it.weight.toUIFontWeight(), it.italic)
} ?: UIFont.systemFontOfSize(textSize.value)
textAlignment = alignment
}

0 comments on commit 7ad6c1c

Please sign in to comment.