Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d8f34b9

Browse files
author
Nurhan Turgut
committed
Adding boolean flags to make conditions more readable. Fixing typos.
1 parent 30cd774 commit d8f34b9

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

lib/web_ui/lib/src/engine/text_editing.dart

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class TextEditingElement {
212212
///
213213
/// In IOS, the virtual keyboard shifts the screen up if the focused input
214214
/// element is under the keyboard or very close to the keyboard. Before the
215-
/// focus is called we are positining it offscreen. The location of the input
215+
/// focus is called we are positioning it offscreen. The location of the input
216216
/// in IOS is set to correct place, 100ms after focus. We use this timer for
217217
/// timing this delay.
218218
Timer _positionInputElementTimer;
@@ -292,8 +292,7 @@ class TextEditingElement {
292292
}));
293293
}
294294

295-
if (browserEngine == BrowserEngine.webkit &&
296-
operatingSystem == OperatingSystem.iOs) {
295+
if (owner.doesKeyboardShiftInput) {
297296
/// Position the element outside of the page before focusing on it.
298297
///
299298
/// See [_positionInputElementTimer].
@@ -625,16 +624,15 @@ class HybridTextEditing {
625624
/// Also used to define if a keyboard is needed.
626625
bool _isEditing = false;
627626

628-
/// Flag indication the input element needs to be positioned.
627+
/// Flag indicating the input element needs to be positioned.
629628
///
630629
/// See [TextEditingElement._delayBeforePositining].
631630
bool get inputElementNeedsToBePositioned =>
632631
!inputPositioned &&
633632
_isEditing &&
634-
browserEngine == BrowserEngine.webkit &&
635-
operatingSystem == OperatingSystem.iOs;
633+
doesKeyboardShiftInput;
636634

637-
/// Flag indication wheterher the input element's position is set.
635+
/// Flag indicating whether the input element's position is set.
638636
///
639637
/// See [inputElementNeedsToBePositioned].
640638
bool inputPositioned = false;
@@ -763,21 +761,30 @@ class HybridTextEditing {
763761
);
764762
}
765763

764+
/// Positioning of input element is only done if we are not expecting input
765+
/// to be shifted by a virtual keyboard or if the input is already positioned.
766+
///
767+
/// Otherwise positioning will be done after focusing on the input.
768+
/// See [TextEditingElement._delayBeforePositining].
769+
bool get _canPositionInput => inputPositioned || !doesKeyboardShiftInput;
770+
771+
/// Flag indicating if virtual keyboard shifts the location of input element.
772+
///
773+
/// Value decided using the operating system and the browser engine.
774+
///
775+
/// In IOS, the virtual keyboard might shifts the screen up to make input
776+
/// visible depending on the location of the focused input element.
777+
bool get doesKeyboardShiftInput =>
778+
browserEngine == BrowserEngine.webkit &&
779+
operatingSystem == OperatingSystem.iOs;
780+
766781
/// These style attributes are dynamic throughout the life time of an input
767782
/// element.
768783
///
769784
/// They are changed depending on the messages coming from method calls:
770785
/// "TextInput.setStyle", "TextInput.setEditableSizeAndTransform".
771-
///
772-
/// In IOS, initial positionig of input element is not done in this method.
773-
/// This method changes the location of the input element if it is already
774-
/// positioned.
775-
/// See [TextEditingElement._delayBeforePositining].
776786
void _setDynamicStyleAttributes(html.HtmlElement domElement) {
777-
if (_editingLocationAndSize != null &&
778-
(inputPositioned ||
779-
!(browserEngine == BrowserEngine.webkit &&
780-
operatingSystem == OperatingSystem.iOs))) {
787+
if (_editingLocationAndSize != null && _canPositionInput) {
781788
setStyle(domElement);
782789
}
783790
}

0 commit comments

Comments
 (0)