Skip to content

Commit 609757d

Browse files
committed
fix(tc): tapping on a tab should navigate straight to the section
1 parent 3545da3 commit 609757d

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

lib/app/features/tokenized_communities/views/pages/tokenized_community_page.dart

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// SPDX-License-Identifier: ice License 1.0
22

3+
import 'dart:async';
4+
35
import 'package:decimal/decimal.dart';
46
import 'package:flutter/material.dart';
57
import 'package:flutter/rendering.dart';
@@ -112,19 +114,42 @@ class TokenizedCommunityPage extends HookConsumerWidget {
112114
final targetCtx = sectionKeys[index].currentContext;
113115
if (targetCtx == null) return;
114116

117+
double outerOffsetDy = 0;
118+
115119
final nestedState = targetCtx.findAncestorStateOfType<NestedScrollViewState>();
116120
final inner = nestedState?.innerController ?? innerScrollController.value;
117121
if (inner == null || !inner.hasClients) return;
118122

119-
final ro = targetCtx.findRenderObject();
123+
final outer = nestedState?.outerController;
124+
if (outer != null && outer.hasClients) {
125+
outerOffsetDy = outer.position.pixels;
126+
final outerTarget = outer.position.maxScrollExtent - (index == 0 ? 40 : 0);
127+
128+
unawaited(
129+
outer.animateTo(
130+
outerTarget,
131+
duration: const Duration(milliseconds: 300),
132+
curve: Curves.easeInOut,
133+
),
134+
);
135+
if (index == 0) {
136+
return;
137+
}
138+
}
139+
140+
final updatedCtx = sectionKeys[index].currentContext;
141+
if (updatedCtx == null) return;
142+
143+
final ro = updatedCtx.findRenderObject();
120144
if (ro == null) return;
121145

122146
final viewport = RenderAbstractViewport.of(ro);
123147

124148
// Align the section to the TOP of the inner viewport.
125149
final desired = viewport.getOffsetToReveal(ro, 0).offset;
126150
final pos = inner.position;
127-
final target = (desired - 110.0).clamp(pos.minScrollExtent, pos.maxScrollExtent);
151+
final target = (desired - (outerOffsetDy == 0 ? 40 : 160))
152+
.clamp(pos.minScrollExtent, pos.maxScrollExtent);
128153

129154
await inner.animateTo(
130155
target,

0 commit comments

Comments
 (0)