Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 7adeeab

Browse files
author
Yuncong Zhang
committed
Update
1 parent cacea5e commit 7adeeab

File tree

1 file changed

+111
-40
lines changed

1 file changed

+111
-40
lines changed

Runtime/material/bottom_navigation_bar.cs

Lines changed: 111 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,78 @@ public _BottomNavigationTile(
104104
public readonly bool selected;
105105
public readonly string indexLabel;
106106

107-
Widget _buildIcon() {
107+
public override Widget build(BuildContext context) {
108+
int size;
109+
Widget label;
110+
switch (this.type) {
111+
case BottomNavigationBarType.fix:
112+
size = 1;
113+
label = new _FixedLabel(colorTween: this.colorTween, animation: this.animation, item: this.item);
114+
break;
115+
case BottomNavigationBarType.shifting:
116+
size = ((this.flex * 1000.0f) ?? 0.0f).round();
117+
label = new _ShiftingLabel(animation: this.animation, item: this.item);
118+
break;
119+
default:
120+
throw new Exception("Unknown BottomNavigationBarType: " + this.type);
121+
}
122+
123+
return new Expanded(
124+
flex: size,
125+
child: new Stack(
126+
children: new List<Widget> {
127+
new InkResponse(
128+
onTap: this.onTap == null ? (GestureTapCallback) null : () => { this.onTap(); },
129+
child: new Column(
130+
crossAxisAlignment: CrossAxisAlignment.center,
131+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
132+
mainAxisSize: MainAxisSize.min,
133+
children: new List<Widget> {
134+
new _TileIcon(
135+
type: this.type,
136+
colorTween: this.colorTween,
137+
animation: this.animation,
138+
iconSize: this.iconSize,
139+
selected: this.selected,
140+
item: this.item
141+
),
142+
label
143+
}
144+
)
145+
)
146+
}
147+
)
148+
);
149+
}
150+
}
151+
152+
153+
class _TileIcon : StatelessWidget {
154+
public _TileIcon(
155+
Key key = null,
156+
BottomNavigationBarType? type = null,
157+
ColorTween colorTween = null,
158+
Animation<float> animation = null,
159+
float? iconSize = null,
160+
bool? selected = null,
161+
BottomNavigationBarItem item = null
162+
) : base(key: key) {
163+
this.type = type;
164+
this.colorTween = colorTween;
165+
this.animation = animation;
166+
this.iconSize = iconSize;
167+
this.selected = selected;
168+
this.item = item;
169+
}
170+
171+
BottomNavigationBarType? type;
172+
ColorTween colorTween;
173+
Animation<float> animation;
174+
float? iconSize;
175+
bool? selected;
176+
BottomNavigationBarItem item;
177+
178+
public override Widget build(BuildContext context) {
108179
float tweenStart;
109180
Color iconColor;
110181
switch (this.type) {
@@ -135,13 +206,30 @@ Widget _buildIcon() {
135206
color: iconColor,
136207
size: this.iconSize
137208
),
138-
child: this.selected ? this.item.activeIcon : this.item.icon
209+
child: this.selected == true ? this.item.activeIcon : this.item.icon
139210
)
140211
)
141212
);
142213
}
214+
}
215+
216+
class _FixedLabel : StatelessWidget {
217+
public _FixedLabel(
218+
Key key = null,
219+
ColorTween colorTween = null,
220+
Animation<float> animation = null,
221+
BottomNavigationBarItem item = null
222+
) : base(key: key) {
223+
this.colorTween = colorTween;
224+
this.animation = animation;
225+
this.item = item;
226+
}
143227

144-
Widget _buildFixedLabel() {
228+
ColorTween colorTween;
229+
Animation<float> animation;
230+
BottomNavigationBarItem item;
231+
232+
public override Widget build(BuildContext context) {
145233
float t = new FloatTween(
146234
begin: BottomNavigationBarUtils._kInactiveFontSize / BottomNavigationBarUtils._kActiveFontSize,
147235
end: 1.0f
@@ -165,8 +253,22 @@ Widget _buildFixedLabel() {
165253
)
166254
);
167255
}
256+
}
168257

169-
Widget _buildShiftingLabel() {
258+
class _ShiftingLabel : StatelessWidget {
259+
public _ShiftingLabel(
260+
Key key = null,
261+
Animation<float> animation = null,
262+
BottomNavigationBarItem item = null
263+
) : base(key: key) {
264+
this.animation = animation;
265+
this.item = item;
266+
}
267+
268+
Animation<float> animation;
269+
BottomNavigationBarItem item;
270+
271+
public override Widget build(BuildContext context) {
170272
return new Align(
171273
alignment: Alignment.bottomCenter,
172274
heightFactor: 1.0f,
@@ -190,42 +292,9 @@ Widget _buildShiftingLabel() {
190292
)
191293
);
192294
}
193-
194-
public override Widget build(BuildContext context) {
195-
int size;
196-
Widget label;
197-
switch (this.type) {
198-
case BottomNavigationBarType.fix:
199-
size = 1;
200-
label = this._buildFixedLabel();
201-
break;
202-
case BottomNavigationBarType.shifting:
203-
size = ((this.flex * 1000.0f) ?? 0.0f).round();
204-
label = this._buildShiftingLabel();
205-
break;
206-
default:
207-
throw new Exception("Unknown BottomNavigationBarType: " + this.type);
208-
}
209-
210-
return new Expanded(
211-
flex: size,
212-
child: new Stack(
213-
children: new List<Widget> {
214-
new InkResponse(
215-
onTap: this.onTap == null ? (GestureTapCallback) null : () => { this.onTap(); },
216-
child: new Column(
217-
crossAxisAlignment: CrossAxisAlignment.center,
218-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
219-
mainAxisSize: MainAxisSize.min,
220-
children: new List<Widget> {this._buildIcon(), label}
221-
)
222-
)
223-
}
224-
)
225-
);
226-
}
227295
}
228296

297+
229298
class _BottomNavigationBarState : TickerProviderStateMixin<BottomNavigationBar> {
230299
public List<AnimationController> _controllers = new List<AnimationController> { };
231300
public List<CurvedAnimation> _animations;
@@ -390,7 +459,8 @@ List<Widget> _createTiles() {
390459
},
391460
colorTween: colorTween,
392461
selected: i == this.widget.currentIndex,
393-
indexLabel: localizations.tabLabel(tabIndex: i + 1, tabCount: this.widget.items.Count)
462+
indexLabel: localizations.tabLabel(tabIndex: i + 1,
463+
tabCount: this.widget.items.Count)
394464
)
395465
);
396466
}
@@ -410,7 +480,8 @@ List<Widget> _createTiles() {
410480
flex:
411481
this._evaluateFlex(this._animations[i]),
412482
selected: i == this.widget.currentIndex,
413-
indexLabel: localizations.tabLabel(tabIndex: i + 1, tabCount: this.widget.items.Count)
483+
indexLabel: localizations.tabLabel(tabIndex: i + 1,
484+
tabCount: this.widget.items.Count)
414485
)
415486
);
416487
}

0 commit comments

Comments
 (0)