Skip to content

Commit 29da0fb

Browse files
authored
chore: comment for why nativeTextViewProtected (NativeScript#8886)
Explains for future generations why this getter exists. 😀
1 parent 13be3d6 commit 29da0fb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/core/ui/text-base/text-base-common.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@ export abstract class TextBaseCommon extends View implements TextBaseDefinition
2626
public text: string;
2727
public formattedText: FormattedString;
2828

29+
/***
30+
* In the NativeScript Core; by default the nativeTextViewProtected points to the same value as nativeViewProtected.
31+
* At this point no internal NS components need this indirection functionality.
32+
* This indirection is used to allow support usage by third party components so they don't have to duplicate functionality.
33+
*
34+
* A third party component can just override the `nativeTextViewProtected` getter and return a different internal view and that view would be
35+
* what all TextView/TextInput class features would be applied to.
36+
*
37+
* A example is the Android MaterialDesign TextInput class, it has a wrapper view of a TextInputLayout
38+
* https://developer.android.com/reference/com/google/android/material/textfield/TextInputLayout
39+
* which wraps the actual TextInput. This wrapper layout (TextInputLayout) must be assigned to the nativeViewProtected as the entire
40+
* NS Core uses nativeViewProtected for everything related to layout, so that it can be measured, added to the parent view as a child, ect.
41+
*
42+
* However, its internal view would be the actual TextView/TextInput and to allow that sub-view to have the normal TextView/TextInput
43+
* class features, which we expose and to allow them to work on it, the internal TextView/TextInput is what the needs to have the class values applied to it.
44+
*
45+
* So all code that works on what is expected to be a TextView/TextInput should use `nativeTextViewProtected` so that any third party
46+
* components that need to have two separate components can work properly without them having to duplicate all the TextBase (and decendants) functionality
47+
* by just overriding the nativeTextViewProtected getter.
48+
**/
2949
get nativeTextViewProtected() {
3050
return this.nativeViewProtected;
3151
}

0 commit comments

Comments
 (0)