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> public class Example01ScrollView : FancyScrollView<Example01CellDto>
{ {
[SerializeField] [SerializeField]
ScrollPositionController scrollPositionController; ScrollPositionController scrollPositionController;

View File

@ -10,6 +10,9 @@ namespace UnityEngine.UI.Extensions.Examples
new void Awake() new void Awake()
{ {
scrollPositionController.OnUpdatePosition.AddListener(UpdatePosition); scrollPositionController.OnUpdatePosition.AddListener(UpdatePosition);
// Add OnItemSelected event listener
scrollPositionController.OnItemSelected.AddListener(CellSelected);
SetContext(new Example02ScrollViewContext { OnPressedCell = OnPressedCell }); SetContext(new Example02ScrollViewContext { OnPressedCell = OnPressedCell });
base.Awake(); base.Awake();
} }
@ -27,5 +30,13 @@ namespace UnityEngine.UI.Extensions.Examples
context.SelectedIndex = cell.DataIndex; context.SelectedIndex = cell.DataIndex;
UpdateContents(); 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() new void Awake()
{ {
scrollPositionController.OnUpdatePosition.AddListener(UpdatePosition); scrollPositionController.OnUpdatePosition.AddListener(UpdatePosition);
// Add OnItemSelected event listener
scrollPositionController.OnItemSelected.AddListener(CellSelected);
SetContext(new Example03ScrollViewContext { OnPressedCell = OnPressedCell }); SetContext(new Example03ScrollViewContext { OnPressedCell = OnPressedCell });
base.Awake(); base.Awake();
} }
@ -28,5 +32,12 @@ namespace UnityEngine.UI.Extensions.Examples
UpdateContents(); 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();
}
} }
} }