[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TabBar tab indicator stretch effect #150868

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TahaTesser
Copy link
Member

fixes [Material3] TabBar indicator stretch effect behaving weirdly with long tabs

This PR fixes the tab indicator stretch effect, it currently stretches from both sides. After the fix, tab indicator stretches depending on next size of the indicator and direction of the scroll.

The fix is based on Android Components implementation of the elastic/stretch effect.

https://github.com/material-components/material-components-android/blob/20f92dfb513916d0df6c38bfd630dfc41aff484e/lib/java/com/google/android/material/tabs/ElasticTabIndicatorInterpolator.java#L46-L78

Code sample

expand to view the code sample
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: ScrollConfiguration(
        behavior: ScrollConfiguration.of(context)
            .copyWith(dragDevices: <PointerDeviceKind>{
          PointerDeviceKind.touch,
          PointerDeviceKind.mouse,
        }),
        child: DefaultTabController(
          length: 8,
          child: Scaffold(
            appBar: AppBar(
              bottom: const TabBar(
                isScrollable: true,
                tabAlignment: TabAlignment.start,
                tabs: <Widget>[
                  Tab(text: 'Home'),
                  Tab(text: 'Search'),
                  Tab(text: 'Add'),
                  Tab(text: 'Favorite'),
                  Tab(text: 'The longest text...'),
                  Tab(text: 'Short'),
                  Tab(text: 'Longer text...'),
                  Tab(text: 'Profile'),
                ],
              ),
            ),
            body: const TabBarView(
              children: <Widget>[
                Center(child: Text('Page')),
                Center(child: Text('Page')),
                Center(child: Text('Page')),
                Center(child: Text('Page')),
                Center(child: Text('Page')),
                Center(child: Text('Page')),
                Center(child: Text('Page')),
                Center(child: Text('Page')),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Before

Screen.Recording.2024-06-26.at.21.26.53.mov

After

Screen.Recording.2024-06-26.at.21.25.50.mov

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Material3] TabBar indicator stretch effect behaving weirdly with long tabs
1 participant