modify
This commit is contained in:
parent
00ae22e155
commit
9987d56adf
@ -116,7 +116,6 @@ namespace AlicizaX.UI.RecyclerView
|
||||
public int CurrentIndex
|
||||
{
|
||||
get => currentIndex;
|
||||
set => currentIndex = value;
|
||||
}
|
||||
|
||||
public bool CanScroll => true;
|
||||
@ -134,7 +133,7 @@ namespace AlicizaX.UI.RecyclerView
|
||||
|
||||
public Scrollbar Scrollbar => _scrollbar;
|
||||
|
||||
private IAdapter Adapter;
|
||||
private IAdapter _adapter;
|
||||
|
||||
public LayoutManager LayoutManager => _layoutManager;
|
||||
|
||||
@ -262,12 +261,12 @@ namespace AlicizaX.UI.RecyclerView
|
||||
|
||||
public void SetAdapter(IAdapter adapter)
|
||||
{
|
||||
Adapter = adapter;
|
||||
ViewProvider.Adapter = Adapter;
|
||||
_adapter = adapter;
|
||||
ViewProvider.Adapter = _adapter;
|
||||
ViewProvider.LayoutManager = _layoutManager;
|
||||
ViewProvider.LayoutManager = _layoutManager;
|
||||
_layoutManager.RecyclerView = this;
|
||||
_layoutManager.Adapter = Adapter;
|
||||
_layoutManager.Adapter = _adapter;
|
||||
_layoutManager.ViewProvider = viewProvider;
|
||||
_layoutManager.Direction = direction;
|
||||
_layoutManager.Alignment = alignment;
|
||||
@ -355,8 +354,8 @@ namespace AlicizaX.UI.RecyclerView
|
||||
Refresh();
|
||||
}
|
||||
|
||||
index %= Adapter.GetItemCount();
|
||||
index = index < 0 ? Adapter.GetItemCount() + index : index;
|
||||
index %= _adapter.GetItemCount();
|
||||
index = index < 0 ? _adapter.GetItemCount() + index : index;
|
||||
|
||||
if (currentIndex != index)
|
||||
{
|
||||
|
@ -23,26 +23,34 @@ namespace AlicizaX.UI.RecyclerView
|
||||
private set { rectTransform = value; }
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public int Index { get; set; }
|
||||
public string Name { get; internal set; }
|
||||
public int Index { get; internal set; }
|
||||
|
||||
public bool ChoiseState { private set; get; }
|
||||
|
||||
public Vector2 SizeDelta => RectTransform.sizeDelta;
|
||||
private IButton _button;
|
||||
|
||||
public virtual void OnStop()
|
||||
protected internal virtual void OnStart()
|
||||
{
|
||||
}
|
||||
|
||||
public abstract void BindViewData<T>(T data);
|
||||
|
||||
public virtual void BindItemClick<T>(T data, Action<T> action)
|
||||
protected internal virtual void OnRecycled()
|
||||
{
|
||||
if (TryGetComponent(out IButton button))
|
||||
{
|
||||
button.onClick.RemoveAllListeners();
|
||||
button.onClick.AddListener(() => action?.Invoke(data));
|
||||
}
|
||||
|
||||
protected internal abstract void BindViewData<T>(T data);
|
||||
|
||||
protected internal virtual void BindItemClick<T>(T data, Action<T> action)
|
||||
{
|
||||
if (_button is null && !TryGetComponent(out _button))
|
||||
{
|
||||
Log.Warning("找不到Button组件");
|
||||
return;
|
||||
}
|
||||
|
||||
_button.onClick.RemoveAllListeners();
|
||||
_button.onClick.AddListener(() => action?.Invoke(data));
|
||||
}
|
||||
|
||||
protected internal void BindChoiceState(bool state)
|
||||
|
@ -44,11 +44,10 @@ namespace AlicizaX.UI.RecyclerView
|
||||
|
||||
string viewName = Adapter.GetViewName(i);
|
||||
var viewHolder = Allocate(viewName);
|
||||
// viewHolder.OnStart();
|
||||
viewHolder.OnStart();
|
||||
viewHolder.Name = viewName;
|
||||
viewHolder.Index = i;
|
||||
viewHolders.Add(viewHolder);
|
||||
|
||||
LayoutManager.Layout(viewHolder, i);
|
||||
Adapter.OnBindViewHolder(viewHolder, i);
|
||||
}
|
||||
@ -66,7 +65,7 @@ namespace AlicizaX.UI.RecyclerView
|
||||
|
||||
var viewHolder = viewHolders[viewHolderIndex];
|
||||
viewHolders.RemoveAt(viewHolderIndex);
|
||||
viewHolder.OnStop();
|
||||
viewHolder.OnRecycled();
|
||||
Free(viewHolder.Name, viewHolder);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user