https://github.com/justinfincher/uiwidgets.scrollabletabview
https://github.com/justinfincher/uiwidgets.scrollabletabview
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/justinfincher/uiwidgets.scrollabletabview
- Owner: JustinFincher
- Created: 2019-05-23T03:38:08.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-23T07:52:43.000Z (over 6 years ago)
- Last Synced: 2025-05-19T01:37:55.902Z (5 months ago)
- Language: C#
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# UIWidgets.ScrollableTabView
> A Chrome-like scrollable tab view widget for UIWidgets# How to add
Add this line to your package.json dependencies list
```
"com.justzht.uiwidgets.scrollabletabview": "https://github.com/JustinFincher/UIWidgets.ScrollableTabView.git"
```# Usage
```csharp
new ScrollableTabView
(
int totalCount = 0, // total tab count
int selectedIndex = -1, // current tab count
Func viewOfIndex = null, // bottom view provider
Func titleOfIndex = null, // title provider
float tabControlLeftPadding = 12,
float tabControlRightPadding = 12,
float tabControlTopPadding = 8,
Action onSelectedIndexChanged = null, // need to change your selectedIndex data in this scope
Action onIndexClosed = null, // need to delete your data item in this
Action onIndexSwitched = null, // need to reorder your data list in this
Key key = null
)
```# Sample
```csharp
using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.widgets;
using UnityEngine;namespace FinGameWorks.Scripts.Views
{
public class AppMainScreen : StatefulWidget
{
public List TabList = new List();
public int ScrollTabIndex = -1;public AppMainScreen(Key key = null) : base(key)
{
for (int i = 0; i < 16; i++)
{
TabList.Add("Tab " + i.ToString());
}
}public override State createState()
{
return new AppMainScreenState();
}
}class AppMainScreenState : State
{
public override Widget build(BuildContext context)
{
return new Scaffold
(
body: new SafeArea
(
child: new ScrollableTabView
(
totalCount:widget.TabList.Count,
selectedIndex:widget.ScrollTabIndex,
tabControlLeftPadding: 16,
tabControlRightPadding:16,
tabControlTopPadding:16,
viewOfIndex: i => { return new Center(child:new Text(widget.TabList[i]));},
titleOfIndex: i => { return widget.TabList[i]; },
onSelectedIndexChanged: i =>
{
setState(() => widget.ScrollTabIndex = i);
},
onIndexClosed: i =>
{
setState(() =>
{
if (widget.ScrollTabIndex >= i)
{
widget.ScrollTabIndex--;
}
widget.TabList.RemoveAt(i);
});
},
onIndexSwitched: (pre, nex) =>
{
setState(() =>
{
widget.ScrollTabIndex = nex;
if (pre < nex)
{
var tmp = widget.TabList[pre];
for (int i = pre; i < nex; i++)
{
widget.TabList[i] = widget.TabList[i + 1];
}
widget.TabList[nex] = tmp;
}
else if (pre > nex)
{
var tmp = widget.TabList[pre];
for (int i = pre; i > nex; i--)
{
widget.TabList[i] = widget.TabList[i - 1];
}
widget.TabList[nex + 1] = tmp;
}
});
}
)
)
);
}
}
}
```