我的目标是拥有一个LoginScreen可以导航到InternalScreen. 应该InternalScreen有一个底部导航栏,可以导航到内部空间中的多个其他屏幕/路线。
这就是我想象中NavGraph的样子:
- LoginScreen
- internal space
- InternalScreen with BottomNavigation
- some fragment
- some other fragment
Run Code Online (Sandbox Code Playgroud)
我的想法是在可组合项中创建一个Scaffold带有 a 的项目,但我不知道将它放在哪里,因为 said还必须包含 的不同路线。BottomNavigationBarInternalScreenNavGraphNavGraphBottomNavigationBar
我应该如何处理这个问题?如果这个问题已经得到解答,我很抱歉,我找不到有关此特定案例的任何信息。
我正在编写一个库,其中包含具有自定义属性的自定义派生宏。为此,我使用darling. 因此,我的项目结构如下:
\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pg-worm\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pg-worm-derive\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src/lib.rs\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src/lib.rs\nRun Code Online (Sandbox Code Playgroud)\n我的 proc 宏是这样指定的 ( pg-worm/pg-worm-derive/src/lib.rs):
use darling::FromDeriveInput;\nuse proc_macro::{self, TokenStream};\nuse syn::parse_macro_input;\n\n#[derive(FromDeriveInput)]\n#[darling(attributes(table))]\nModelInput {\n table_name: Option<String>\n}\n\n#[proc_macro_derive(Model)]\npub fn derive(input: TokenStream) -> TokenStream {\n let opts = ModelInput::from_derive_input(&parse_macro_input!(input)).unwrap();\n\n // macro magic happens\n}\nRun Code Online (Sandbox Code Playgroud)\n然后我从主文件 ( pg-worm/src/lib.rs) 中重新导出宏:
pub use pg_worm_derive::*;\n\npub trait Model {\n // trait specs\n}\nRun Code Online (Sandbox Code Playgroud)\n但是当我使用以下代码测试我的宏时(也在pg-worm/src/lib.rs):
#[cfg(test)]\nmod tests {\n use pg_worm::Model;\n\n #[derive(Model)]\n #[table(table_name = "person")]\n struct Person {\n id: i64,\n name: …Run Code Online (Sandbox Code Playgroud) 我的应用程序需要一个底部导航栏。显示我使用的项目BottomNavigationItem:
BottomNavigation(
...
) {
...
BottomNavigationItem(
...
onClick = {onItemSelect(item)},
...
)
}
Run Code Online (Sandbox Code Playgroud)
然而,这些会带来连锁反应,我想禁用它,尽管我不知道如何禁用。需要BottomNavigationItem该属性,因此不能选择onClick使用修饰符。.clickable()
编辑:
Gabriele Mariotti 的这个回答MutableInteractionSource建议将 a 传递给.clickable函数,以及nullfor indication。虽然BottomNavigationItem接受 a MutableInteractionSource,但它似乎不接受 an indication。
我有一个无法更改的闭包,我需要在新线程中运行它并且需要向其传递一个变量。这就是我想象的代码的样子:
use std::thread;
fn main() {
// I can not influence this closure, but this is what it looks like
let handle = move |data: i32| {
println!("Got {data}")
};
let foo = 123;
// This doesn't work
thread::spawn(handle).arg(foo).join()
}
Run Code Online (Sandbox Code Playgroud)
Python 中的等效代码确实可以工作,所以我想知道这在 Rust 中是否可行,如果可以,那么如何实现。
先感谢您。