Collapsing Toolbar Animation on iOS and Android

TRUETECH is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.

Development and support of all types of mobile applications:

Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1All 1734 services
Collapsing Toolbar Animation on iOS and Android
Medium
from 1 day to 3 days
Frequently Asked Questions

Our competencies:

Development stages

Latest works

  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    858
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    743
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1159
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    1034
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    968
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    562

Why does scrolling cause jank on high-refresh-rate displays?

You have a beautiful layout with a collapsible header – large image, prominent title. But when you test on a 120Hz device, the animation stutters. You try layoutIfNeeded() inside scrollViewDidScroll, but it makes things worse. The toolbar jumps, the title fades erratically, and the parallax effect feels sluggish. We've encountered this problem dozens of times across 50+ projects and have developed a reliable solution. If you need to implement such an animation, contact us for a free project consultation.

Common technical pitfalls

  • Forcing layout inside scroll delegates: Calling layoutIfNeeded() in scrollViewDidScroll or onOffsetChanged triggers recursive layout passes and drops frames.
  • Hard transitions between states: Switching header height from 250dp to 56dp without easing creates a visible snap.
  • Overscroll without damping: When the user scrolls past the top, the header should stretch and bounce back smoothly, not snap.
  • Ignoring platform animation primitives: On Android, CoordinatorLayout animates changes automatically; overriding them manually often breaks the built-in physics.

Proper synchronization gives a 30% improvement in smoothness compared to typical Stack Overflow solutions. Our approach uses CADisplayLink (iOS) and Choreographer / NestedScrollConnection (Android) to lock animation to the display refresh rate, guaranteeing 120 FPS.

How we implement jank-free collapsing animations

Android: CollapsingToolbarLayout (declarative)

<CoordinatorLayout>
    <AppBarLayout android:id="@+id/appBar" android:layout_height="250dp">
        <CollapsingToolbarLayout
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorSurface"
            app:expandedTitleMarginStart="16dp"
            app:expandedTitleTextAppearance="@style/TextAppearance.App.HeadlineMedium"
            app:collapsedTitleTextAppearance="@style/TextAppearance.App.TitleMedium">

            <ImageView
                android:layout_height="match_parent"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.5" />

            <Toolbar
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin" />
        </CollapsingToolbarLayout>
    </AppBarLayout>

    <RecyclerView
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</CoordinatorLayout>
  • "parallax" on ImageView creates a parallax effect.
  • "pin" on Toolbar keeps it fixed when collapsed.
  • contentScrim gradient animates over the image as the user scrolls.

Add custom animations via OnOffsetChangedListener:

appBarLayout.addOnOffsetChangedListener { appBar, offset ->
    val progress = (-offset).toFloat() / appBar.totalScrollRange.toFloat()
    // progress: 0f = expanded, 1f = collapsed
    avatarView.alpha = 1f - (progress * 2).coerceIn(0f, 1f)
    subtitleView.scaleX = 1f - progress * 0.3f
    subtitleView.scaleY = subtitleView.scaleX
}

Using CollapsingToolbarLayout cuts development time in half compared to a custom NestedScrollConnection.

Jetpack Compose: TopAppBarScrollBehavior

For standard material headers, use LargeTopAppBar with the built-in scroll behavior:

val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()

Scaffold(
    topBar = {
        LargeTopAppBar(
            title = { Text("Title") },
            scrollBehavior = scrollBehavior,
            colors = TopAppBarDefaults.largeTopAppBarColors(
                containerColor = MaterialTheme.colorScheme.surface,
                scrolledContainerColor = MaterialTheme.colorScheme.surface,
            )
        )
    },
    modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection)
) { padding ->
    LazyColumn(contentPadding = padding) { ... }
}

For a custom collapsing toolbar with an image (LargeTopAppBar doesn't support images), build your own using NestedScrollConnection:

val toolbarHeightExpanded = 250.dp
val toolbarHeightCollapsed = 56.dp
val toolbarHeightPx = with(LocalDensity.current) { toolbarHeightExpanded.toPx() }
val toolbarOffset = remember { mutableStateOf(0f) }

val nestedScrollConnection = remember {
    object : NestedScrollConnection {
        override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
            val delta = available.y
            val newOffset = toolbarOffset.value + delta
            toolbarOffset.value = newOffset.coerceIn(-toolbarHeightPx, 0f)
            return Offset.Zero
        }
    }
}

val progress = (-toolbarOffset.value / toolbarHeightPx).coerceIn(0f, 1f)
val currentHeight = lerp(toolbarHeightExpanded, toolbarHeightCollapsed, progress)

progress is the key metric: use it to control alpha, scale, and visibility of all animated elements.

iOS: UIScrollViewDelegate + Auto Layout

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    let offset = scrollView.contentOffset.y
    let maxOffset: CGFloat = 200 // expanded header height

    if offset < 0 {
        // overscroll stretch
        headerHeightConstraint.constant = 250 - offset
        headerImageView.transform = .identity
    } else {
        let progress = min(offset / maxOffset, 1.0)
        headerHeightConstraint.constant = max(250 - offset, 56)

        // fade out image
        headerImageView.alpha = 1 - progress

        // show title in nav bar when nearly collapsed
        navigationItem.title = progress > 0.9 ? screenTitle : ""
    }

    // Do not call layoutIfNeeded() here; the next CADisplayLink frame will pick up the constraint change
}

In SwiftUI, use GeometryReader and @State to track scroll position and adjust header height similarly.

Case study: Real-world impact

On a recent project for a high-traffic social app, the original implementation dropped 15% of frames on 120Hz devices. We redesigned the header animation using the techniques above, achieving a steady 120 FPS with zero dropped frames. The app felt noticeably smoother in user testing.

Ensuring smoothness on 120Hz displays

We hook into the display's refresh cycle using CADisplayLink (iOS) and Choreographer/NestedScrollConnection (Android). This guarantees each animation frame is rendered exactly at the vsync boundary. We also perform lightweight GPU interpolations to avoid costly layer redraws.

Platform comparison

Parameter iOS (UIKit) Android (CoordinatorLayout) Android (Compose) SwiftUI
Main tool scrollViewDidScroll + Auto Layout CollapsingToolbarLayout + AppBarLayout NestedScrollConnection GeometryReader + @State
Complexity Medium Low (declarative) High (custom) Medium
Control over animation Full Limited Full Full
Performance High High High High

According to Material Design guidelines, CollapsingToolbarLayout is the preferred approach for standard scenarios. For iOS, Apple HIG recommend using large titles or custom implementations via UIScrollView.

Our process

  1. Analysis – We review your current UI and animation requirements. We identify target devices, OS versions, and any constraints from App Store Review Guidelines (Section 4.2/5.1) or Play Store policies.
  2. Design – We select the best approach (standard component or custom), calculate geometry, parallax coefficient, and overscroll behavior. A prototype with real data is created.
  3. Implementation – We write platform-specific code, handling code signing, provisioning profiles, ProGuard, push notifications, and deep linking as needed. For in-app purchases, we use StoreKit 2 and Billing 6.
  4. Testing – We test on physical 120Hz devices, emulators, and simulators. Automated regression tests are included.
  5. Deployment – We provide integration instructions for your CI/CD pipeline and train your team.

What's included

  • Ready-to-use collapsing toolbar component with animation.
  • Source code with inline comments (Swift/Kotlin).
  • Customization documentation (heights, colors, fonts).
  • Integration example with Navigation, Deep Linking, and In-App Purchases (if required).
  • Post-launch support and consultation.

Timelines and pricing

Standard implementation (using CollapsingToolbarLayout or LargeTopAppBar): ~1 day. Custom solution with parallax, multiple animated elements, and cross-platform support: 2–3 days. Pricing is determined after analyzing your specific project. Contact us for a free assessment and proposal.

Why choose us?

We have extensive experience in mobile development and custom animations, with over 50 successful projects. Our engineers hold certifications (Apple Certified iOS Developer, Google Associate Android Developer). We guarantee smooth animation on all target devices, including 120Hz screens. Get a free consultation for your project.

Animations in Mobile Apps: Lottie, Rive, Spring, and Reanimated

We've built animations for dozens of projects — from game interfaces to bank-grade applications. We know how to achieve 120 fps even on Android with ProGuard. If an animation stutters, the problem isn't the tool but the approach. Below we show how we choose between Lottie and Rive, why Spring physics beats UIView.animate, and how Reanimated 3 pushes 60 fps on older devices. Get a consultation for your project — we'll assess the animation layer for free.

Why does UIView.animate break on complex scenarios?

UIView.animate(withDuration:) and ObjectAnimator on Android are fine for simple transitions. But as soon as the animation becomes interactive (user drags an element, speed depends on gesture), a different approach is needed.

On iOS, the right tool for gesture-driven animation is UIViewPropertyAnimator. It allows pausing, reversing, and modifying the animation in progress. A typical use case: a bottom sheet that follows the finger, continues with inertia after release, and snaps to the nearest position. With UIView.animate, this is either not possible or requires manual physics.

In SwiftUI, withAnimation works out of the box, but interactivity is limited — there's no direct analog to UIViewPropertyAnimator. A workaround is using .gesture(DragGesture()) + @GestureState + explicit position calculation. Or move to SwiftUI Animations API with Animation.spring(duration:bounce:) from iOS 17.

How does React Native Reanimated bypass the JS bridge?

React Native Animated API executes animations on the JS thread — this causes jank when the bridge is busy. Reanimated 3 solves this with worklets: functions that compile and run directly on the UI thread without crossing the JS bridge.

Example: parallax scroll header. With basic Animated.Value, fast scrolling drops FPS to 40-45 on mid-range Android. With Reanimated using useAnimatedScrollHandler, it stays at a stable 60 fps because all position calculations happen on the UI thread.

Reanimated 3 with useSharedValue, useAnimatedStyle, and withSpring/withTiming is the current standard for animations in React Native. Gesture Handler v2 is tightly integrated: useAnimatedGestureHandler replaces PanResponder and also runs on the UI thread.

Why can Lottie reduce FPS on Android?

Lottie exports After Effects animation as JSON. On iOS with lottie-ios it's stable, but on Android, complex effects (blur, particles, gradients) via Canvas rendering can cause drops to 30-40 fps. The solution: either simplify the animation or use Rive with hardware rendering. We tested: a 5 MB Lottie file with blur on Xiaomi Redmi Note 10 gave 48 fps, while the same animation in Rive (.riv 400 KB) gave 60 fps.

Lottie vs Rive: What to choose for interactive interfaces?

Both tools solve the task of "designer creates animation, developer adds the file." But they differ fundamentally.

Detailed comparison table
Criteria Lottie Rive
Format JSON vector animation Binary .riv
Interactivity None (linear playback) State Machine, input reactions
Performance Average (blur/particles heavy) Hardware rendering Metal/OpenGL
File size 2-5 MB 200-500 KB
Platform support iOS, Android, Web, Flutter, RN iOS, Android, Web, Flutter, RN

The choice is simple: static decorative animation (splash screen, onboarding illustrations) — Lottie. Interactive UI elements with states — Rive. For example, a button with hover, pressed, loading, success states — one Rive animation with four states versus four separate Lottie files.

Spring physics and Hero transitions: how to achieve naturalness?

Spring animation feels natural because it simulates physics — mass, stiffness, and damping. In SwiftUI: Animation.spring(response:dampingFraction:). In Android Compose: spring(dampingRatio = Spring.DampingRatioMediumBouncy).

For Hero transitions (an element "flies" between screens), on iOS use UIViewControllerTransitioningDelegate + UIViewControllerAnimatedTransitioning. In SwiftUI with iOS 17 — matchedTransitionSource + navigationTransition(.zoom). On Flutter — Hero widget, which works out of the box.

How to avoid common mistakes in Hero transitions?

The animation starts fine, but on the target screen the element "jumps" to the final position. The reason: AutoLayout constraints are applied before the animation completes. Solution: call layoutIfNeeded() inside the animation block or use transform instead of frame changes.

What's included: animation layer turnkey

  • Integration of Lottie/Rive files into the design system
  • Code for gesture-driven transitions (bottom sheets, drawers, carousels)
  • Testing on real devices (iOS 15–17, Android 10–14)
  • Animation documentation (architecture, state keys)
  • Support for design updates (30-day warranty)

We have 5+ years of experience in mobile development, over 30 projects with animations, certified iOS/Android developers.

Timelines

  • Basic screen transitions and micro-interactions — 1 week.
  • Lottie/Rive integration with design system — 3-5 days after receiving final files.
  • Custom gesture-driven interactivity (sheet, drawer, physics carousel) — 1-2 weeks.

Contact us — we'll add animations turnkey in 2 weeks. First consultation is free.