Skip to content

Commit d81572f

Browse files
committed
docs(components/bottom_nav_bar): add Bottom Navigation Bar docs and preview video
1 parent 6945f9a commit d81572f

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: Bottom Navigation Bar
3+
order: 20
4+
---
5+
6+
# Bottom Navigation Bar
7+
8+
```rust
9+
pub fn bottom_nav_bar<F>(state: Arc<RwLock<BottomNavBarState>>, scope_config: F)
10+
where
11+
F: FnOnce(&mut BottomNavBarScope<'_>),
12+
```
13+
14+
The `bottom_nav_bar` component is an interactive bottom navigation bar that allows users to switch between multiple navigation items.
15+
16+
## Arguments
17+
18+
- `state: Arc<RwLock<BottomNavBarState>>`
19+
20+
This argument manages the bottom navigation bar's state, including the currently selected item index and animation progress. It can also be used to get the current/previous selected index.
21+
22+
- `scope_config: F`
23+
24+
A closure used to configure the navigation items of the `bottom_nav_bar`. The closure receives a `&mut BottomNavBarScope`; use its `child` method to add navigation items. Its signature is:
25+
26+
```rust
27+
pub fn child<C, O>(&mut self, child: C, on_click: O)
28+
where
29+
C: FnOnce() + Send + Sync + 'static,
30+
O: FnOnce() + Send + Sync + 'static,
31+
```
32+
33+
Where `child` is a tessera component closure for the navigation item, and `on_click` is a callback closure invoked when the item is clicked — you should perform the actual navigation action inside it.
34+
35+
For example, you can use tessera's shard-based navigation in the `on_click` closure. Here's an example:
36+
37+
```rust
38+
// Add the "Profile" item.
39+
nav_scope.child(
40+
|| text(TextArgsBuilder::default().text("Profile".to_string()).build().unwrap()),
41+
move || {
42+
Router::with_mut(|router| {
43+
router.reset_with(ProfileScreenDestination {});
44+
});
45+
},
46+
);
47+
```
48+
49+
## Preview
50+
51+
<video autoplay loop muted>
52+
53+
<source src="/bottom_nav_bar_example.mp4" type="video/mp4">
54+
Your browser does not support the video tag
55+
</video>
164 KB
Binary file not shown.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: Bottom Navigation Bar 组件
3+
order: 20
4+
---
5+
6+
# Bottom Navigation Bar
7+
8+
```rust
9+
pub fn bottom_nav_bar<F>(state: Arc<RwLock<BottomNavBarState>>, scope_config: F)
10+
where
11+
F: FnOnce(&mut BottomNavBarScope<'_>),
12+
```
13+
14+
`bottom_nav_bar` 组件是一个交互式的底部导航栏组件,允许用户在多个导航项之间切换。
15+
16+
## 参数
17+
18+
- `state: Arc<RwLock<BottomNavBarState>>`
19+
20+
此参数管理底部导航栏的状态,包括当前选中的导航项索引和动画进度等。值得一提的是也可以使用它获取当前/上次选中的导航项索引。
21+
22+
- `scope_config: F`
23+
24+
此参数是一个闭包,用于配置 `bottom_nav_bar` 组件的导航项。闭包接受一个 `&mut BottomNavBarScope` 参数,使用它的 `child` 方法来添加导航项。其方法签名如下:
25+
26+
```rust
27+
pub fn child<C, O>(&mut self, child: C, on_click: O)
28+
where
29+
C: FnOnce() + Send + Sync + 'static,
30+
O: FnOnce() + Send + Sync + 'static,
31+
```
32+
33+
其中, `child` 为导航项的 `tessera` 组件闭包,`on_click` 为点击导航项时的回调闭包,用户需要在其中调用实际的导航操作。
34+
35+
举例说,可以在 `on_click` 闭包中使用 `tessera` 的 `shard` 导航特性,下面是一个例子
36+
37+
```rust
38+
// Add the "Profile" item.
39+
nav_scope.child(
40+
|| text(TextArgsBuilder::default().text("Profile".to_string()).build().unwrap()),
41+
move || {
42+
Router::with_mut(|router| {
43+
router.reset_with(ProfileScreenDestination {});
44+
});
45+
},
46+
);
47+
```
48+
49+
## 预览
50+
51+
<video autoplay loop muted>
52+
53+
<source src="/bottom_nav_bar_example.mp4" type="video/mp4">
54+
Your browser does not support the video tag
55+
</video>

0 commit comments

Comments
 (0)