Skip to content

Commit

Permalink
fix: prevent double field initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
mopsicus committed Aug 27, 2024
1 parent a013a6c commit ff34957
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Runtime/MobileInputField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ public enum ReturnKeyType {
bool _isMobileInputCreated = false;

/// <summary>
/// Mobile input first creation flag
/// Mobile input init start flag
/// </summary>
bool _isFirstCreation = true;
bool _initStarted = false;

/// <summary>
/// InputField object
Expand Down Expand Up @@ -271,8 +271,9 @@ void Awake() {
/// </summary>
protected override void Start() {
base.Start();
StartCoroutine(InitProcess());
_isFirstCreation = false;
if (!_initStarted) {
StartCoroutine(InitProcess());
}
}

/// <summary>
Expand All @@ -282,7 +283,7 @@ void OnEnable() {
if (_isMobileInputCreated) {
SetRectNative(this._inputObjectText.rectTransform);
SetVisible(true);
} else if (!_isFirstCreation) {
} else if (!_initStarted) {
StartCoroutine(InitProcess());
}
}
Expand Down Expand Up @@ -363,6 +364,10 @@ public string Text {
/// Initialization
/// </summary>
IEnumerator InitProcess() {
if (_initStarted) {
yield break;
}
_initStarted = true;
yield return WaitForEndOfFrame;
PrepareNativeEdit();
#if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
Expand Down

0 comments on commit ff34957

Please sign in to comment.