Skip to content

Commit

Permalink
PR update
Browse files Browse the repository at this point in the history
  • Loading branch information
angelosilvestre committed Apr 27, 2023
1 parent 5cfc404 commit ed35972
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1186,11 +1186,7 @@ class SuperTextFieldScrollviewState extends State<SuperTextFieldScrollview> with
final extentLineIndex = (extentOffset.dy / widget.estimatedLineHeight).round();

final firstCharY = _textLayout.getCharacterBox(const TextPosition(offset: 0))?.top ?? 0.0;
final lastCharY =
_textLayout.getCharacterBox(TextPosition(offset: widget.textController.text.text.length - 1))?.top ?? 0.0;

final isAtFirstLine = extentOffset.dy == firstCharY;
final isAtLastLine = extentOffset.dy == lastCharY;

final myBox = context.findRenderObject() as RenderBox;
final beyondTopExtent = min<double>(
Expand All @@ -1200,6 +1196,11 @@ class SuperTextFieldScrollviewState extends State<SuperTextFieldScrollview> with
(isAtFirstLine ? _textLayout.getLineHeightAtPosition(selection.extent) / 2 : 0),
0)
.abs();

final lastCharY =
_textLayout.getCharacterBox(TextPosition(offset: widget.textController.text.text.length - 1))?.top ?? 0.0;
final isAtLastLine = extentOffset.dy == lastCharY;

final beyondBottomExtent = max<double>(
((extentLineIndex + 1) * widget.estimatedLineHeight) -
myBox.size.height -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,23 +1003,23 @@ class TextScrollController with ChangeNotifier {
_log.finer('Ensuring rect is visible: $rectInContentSpace');
if (_delegate!.isMultiline) {
final firstCharRect = _delegate!.getCharacterRectAtPosition(const TextPosition(offset: 0));
final isAtFirstLine = rectInContentSpace.top == firstCharRect.top;
final extraSpacingAboveTop = (isAtFirstLine ? rectInContentSpace.height / 2 : 0);

final lastCharRect =
_delegate!.getCharacterRectAtPosition(TextPosition(offset: _textController.text.text.length - 1));

final isAtFirstLine = rectInContentSpace.top == firstCharRect.top;
final isAtLastLine = rectInContentSpace.top == lastCharRect.top;
final extraSpacingBelowBottom = (isAtLastLine ? rectInContentSpace.height / 2 : 0);

if (rectInContentSpace.top - (isAtFirstLine ? rectInContentSpace.height / 2 : 0) - _scrollOffset < 0) {
if (rectInContentSpace.top - extraSpacingAboveTop - _scrollOffset < 0) {
// The character is entirely or partially above the top of the viewport.
// Scroll the content down.
_scrollOffset = max(rectInContentSpace.top - (isAtFirstLine ? rectInContentSpace.height / 2 : 0), 0);
_scrollOffset = max(rectInContentSpace.top - extraSpacingAboveTop, 0);
_log.finer(' - updated _scrollOffset to $_scrollOffset');
} else if (rectInContentSpace.bottom - _scrollOffset + (isAtLastLine ? rectInContentSpace.height / 2 : 0) >
_delegate!.viewportHeight!) {
} else if (rectInContentSpace.bottom - _scrollOffset + extraSpacingBelowBottom > _delegate!.viewportHeight!) {
// The character is entirely or partially below the bottom of the viewport.
// Scroll the content up.
_scrollOffset = min(
rectInContentSpace.bottom - _delegate!.viewportHeight! + (isAtLastLine ? rectInContentSpace.height / 2 : 0),
_scrollOffset = min(rectInContentSpace.bottom - _delegate!.viewportHeight! + extraSpacingBelowBottom,
_delegate!.endScrollOffset);
_log.finer(' - updated _scrollOffset to $_scrollOffset');
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ void main() {
text: AttributedText(text: "First line\nSecond Line\nThird Line\nFourth Line"),
);

const description =
'A SuperTextField scrolled to the end should have the last line fully visible with space below it';

// Use a Row as a wrapper to fill the available width.
final builder = GoldenBuilder.column(
wrap: (child) => Row(
children: [child],
),
)
..addScenario(
'SuperTextField with padding, scrolled to the end (on Android)',
'$description (on Android)',
_buildTextField(
textController: controller,
minLines: 1,
Expand All @@ -29,7 +32,7 @@ void main() {
),
)
..addScenario(
'SuperTextField with padding, scrolled to the end (on iOS)',
'$description (on iOS)',
_buildTextField(
textController: controller,
minLines: 1,
Expand All @@ -41,7 +44,7 @@ void main() {
),
)
..addScenario(
'SuperTextField with padding, scrolled to the end (on Desktop)',
'$description (on Desktop)',
_buildTextField(
textController: controller,
minLines: 1,
Expand All @@ -67,14 +70,17 @@ void main() {
text: AttributedText(text: "First line\nSecond Line\nThird Line\nFourth Line"),
);

const description =
'A SuperTextField scrolled to the beginning should have the first line fully visible with space above it';

// Use a Row as a wrapper to fill the available width.
final builder = GoldenBuilder.column(
wrap: (child) => Row(
children: [child],
),
)
..addScenario(
'SuperTextField with padding, scrolled to the beginning (on Android)',
'$description (on Android)',
_buildTextField(
textController: controller,
minLines: 1,
Expand All @@ -86,7 +92,7 @@ void main() {
),
)
..addScenario(
'SuperTextField with padding, scrolled to the beginning (on iOS)',
'$description (on iOS)',
_buildTextField(
textController: controller,
minLines: 1,
Expand All @@ -98,7 +104,7 @@ void main() {
),
)
..addScenario(
'SuperTextField with padding, scrolled to the beginning (on Desktop)',
'$description (on Desktop)',
_buildTextField(
textController: controller,
minLines: 1,
Expand Down

0 comments on commit ed35972

Please sign in to comment.