Skip to content

Commit 2fa7b93

Browse files
committed
Compute Duck.ai intro view height via TypedValue so it honors non-linear sp
1 parent f8fff11 commit 2fa7b93

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

app/src/main/java/com/duckduckgo/app/onboarding/ui/page/BrandDesignUpdateWelcomePage.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,18 @@ class BrandDesignUpdateWelcomePage : OnboardingPageFragment(R.layout.content_onb
403403
}
404404
}
405405

406+
private fun sizeDuckAiIntroAnimationToTextSp() {
407+
val targetTextPx = TypedValue.applyDimension(
408+
TypedValue.COMPLEX_UNIT_SP,
409+
DUCK_AI_INTRO_TEXT_SP,
410+
resources.displayMetrics,
411+
)
412+
val viewHeightPx = (targetTextPx * DUCK_AI_INTRO_CANVAS_H / DUCK_AI_INTRO_TEXT_CANVAS_UNITS).toInt()
413+
binding.duckAiIntroAnimation.updateLayoutParams {
414+
height = viewHeightPx
415+
}
416+
}
417+
406418
private fun prepareDuckAiIntroAnimation() {
407419
binding.duckAiIntroAnimation.apply {
408420
setTextDelegate(
@@ -495,6 +507,8 @@ class BrandDesignUpdateWelcomePage : OnboardingPageFragment(R.layout.content_onb
495507
) {
496508
super.onViewCreated(view, savedInstanceState)
497509

510+
sizeDuckAiIntroAnimationToTextSp()
511+
498512
ViewGroupCompat.installCompatInsetsDispatch(binding.root)
499513
if (deviceInfo.isTablet()) {
500514
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { v, windowInsets ->
@@ -2255,6 +2269,12 @@ class BrandDesignUpdateWelcomePage : OnboardingPageFragment(R.layout.content_onb
22552269
private const val GUIDELINE_START_PERCENT = 0.5f
22562270
private const val GUIDELINE_END_PERCENT = 0.39125f
22572271

2272+
// Sizes the Duck.ai intro Lottie so its baked-in text renders at DUCK_AI_INTRO_TEXT_SP.
2273+
// Derived from the JSON's font-size scale chain: 24 * 3.4 * 0.78 * 1.085 ≈ 69 canvas units at end state.
2274+
private const val DUCK_AI_INTRO_TEXT_SP = 24f
2275+
private const val DUCK_AI_INTRO_CANVAS_H = 260f
2276+
private const val DUCK_AI_INTRO_TEXT_CANVAS_UNITS = 69f
2277+
22582278
private const val TEXT_INTRO_DELAY = 400L
22592279
private const val TEXT_INTRO_OPACITY_DURATION = 400L
22602280
private const val TEXT_INTRO_TRANSLATE_DURATION = 600L

0 commit comments

Comments
 (0)