FancyScrollView control updated to add an event when the page is changed / Selected

Thanks to @ChongHann (Hann Chong) for the fix

Resolves #157
pull/413/head
Simon Jackson 2017-08-07 19:33:53 +01:00
parent adb09d3481
commit b4a2e81aae
3 changed files with 45 additions and 24 deletions

View File

@ -4,7 +4,6 @@ namespace UnityEngine.UI.Extensions.Examples
{
public class Example01ScrollView : FancyScrollView<Example01CellDto>
{
[SerializeField]
ScrollPositionController scrollPositionController;

View File

@ -2,30 +2,41 @@
namespace UnityEngine.UI.Extensions.Examples
{
public class Example02ScrollView : FancyScrollView<Example02CellDto, Example02ScrollViewContext>
{
[SerializeField]
ScrollPositionController scrollPositionController;
public class Example02ScrollView : FancyScrollView<Example02CellDto, Example02ScrollViewContext>
{
[SerializeField]
ScrollPositionController scrollPositionController;
new void Awake()
{
scrollPositionController.OnUpdatePosition.AddListener(UpdatePosition);
SetContext(new Example02ScrollViewContext { OnPressedCell = OnPressedCell });
base.Awake();
}
new void Awake()
{
scrollPositionController.OnUpdatePosition.AddListener(UpdatePosition);
// Add OnItemSelected event listener
scrollPositionController.OnItemSelected.AddListener(CellSelected);
public void UpdateData(List<Example02CellDto> data)
{
cellData = data;
scrollPositionController.SetDataCount(cellData.Count);
UpdateContents();
}
SetContext(new Example02ScrollViewContext { OnPressedCell = OnPressedCell });
base.Awake();
}
void OnPressedCell(Example02ScrollViewCell cell)
{
scrollPositionController.ScrollTo(cell.DataIndex, 0.4f);
context.SelectedIndex = cell.DataIndex;
UpdateContents();
}
}
public void UpdateData(List<Example02CellDto> data)
{
cellData = data;
scrollPositionController.SetDataCount(cellData.Count);
UpdateContents();
}
void OnPressedCell(Example02ScrollViewCell cell)
{
scrollPositionController.ScrollTo(cell.DataIndex, 0.4f);
context.SelectedIndex = cell.DataIndex;
UpdateContents();
}
// An event triggered when a cell is selected.
void CellSelected(int cellIndex)
{
// Update context.SelectedIndex and call UpdateContents for updating cell's content.
context.SelectedIndex = cellIndex;
UpdateContents();
}
}
}

View File

@ -10,6 +10,10 @@ namespace UnityEngine.UI.Extensions.Examples
new void Awake()
{
scrollPositionController.OnUpdatePosition.AddListener(UpdatePosition);
// Add OnItemSelected event listener
scrollPositionController.OnItemSelected.AddListener(CellSelected);
SetContext(new Example03ScrollViewContext { OnPressedCell = OnPressedCell });
base.Awake();
}
@ -28,5 +32,12 @@ namespace UnityEngine.UI.Extensions.Examples
UpdateContents();
}
// An event triggered when a cell is selected.
void CellSelected(int cellIndex)
{
// Update context.SelectedIndex and call UpdateContents for updating cell's content.
context.SelectedIndex = cellIndex;
UpdateContents();
}
}
}