feat(task-0004): add ViewModel layer and improve UIView initialization safety
- Create SplashUIViewModel, MenuUIViewModel and LoadingUIViewModel classes implementing IUIViewModel - Convert UI views to use generic UIView<TVm> pattern for strong typing - Bind ViewModels in state EnterAsync methods before view initialization - Add null check validation in UIView.Bind method with ArgumentNullException - Track initialization state with _isInitialized flag to prevent duplicate Initialize/Release calls Выполнена задача TASK-0004 и добавлен слой ViewModel: - Созданы классы SplashUIViewModel, MenuUIViewModel и LoadingUIViewModel с реализацией IUIViewModel - Преобразованы UI представления для использования общего паттерна UIView<TVm> - Добавлено связывание ViewModels в методах EnterAsync состояний перед инициализацией вида - Добавлена проверка на null в методе Bind с выбросом ArgumentNullException - Добавлен флаг _isInitialized для предотвращения повторных вызовов Initialize/Release
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using System;
|
||||
|
||||
namespace QuizPleaseTest.Common.UI
|
||||
{
|
||||
public class UIView<TVm> : UIView where TVm : IUIViewModel
|
||||
@@ -6,6 +8,11 @@ namespace QuizPleaseTest.Common.UI
|
||||
|
||||
public virtual void Bind(TVm viewModel)
|
||||
{
|
||||
if (viewModel == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(viewModel));
|
||||
}
|
||||
|
||||
ViewModel = viewModel;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,27 @@ namespace QuizPleaseTest.Common.UI
|
||||
{
|
||||
public class UIView : MonoBehaviour
|
||||
{
|
||||
private bool _isInitialized;
|
||||
|
||||
public virtual void Initialize()
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isInitialized = true;
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public virtual void Release()
|
||||
{
|
||||
if (!_isInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isInitialized = false;
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user