小编Ein*_*che的帖子

Jetpack Compose 导航:登录屏幕和带有底部导航的不同屏幕

我的目标是拥有一个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

我应该如何处理这个问题?如果这个问题已经得到解答,我很抱歉,我找不到有关此特定案例的任何信息。

android-jetpack-compose jetpack-compose-navigation

9
推荐指数
1
解决办法
4760
查看次数

错误:当使用自定义 proc_macro 以及用 Rust 中的 darling 编写的属性时,“无法在此范围内找到属性”

我正在编写一个库,其中包含具有自定义属性的自定义派生宏。为此,我使用darling. 因此,我的项目结构如下:

\n
\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\n
Run Code Online (Sandbox Code Playgroud)\n

我的 proc 宏是这样指定的 ( pg-worm/pg-worm-derive/src/lib.rs):

\n
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}\n
Run Code Online (Sandbox Code Playgroud)\n

然后我从主文件 ( pg-worm/src/lib.rs) 中重新导出宏:

\n
pub use pg_worm_derive::*;\n\npub trait Model {\n    // trait specs\n}\n
Run Code Online (Sandbox Code Playgroud)\n

但是当我使用以下代码测试我的宏时(也在pg-worm/src/lib.rs):

\n
#[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)

rust rust-proc-macros rust-attributes

4
推荐指数
1
解决办法
1220
查看次数

禁用 BottomNavigationItem 的涟漪效果

我的应用程序需要一个底部导航栏。显示我使用的项目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

android-jetpack-navigation android-jetpack-compose

3
推荐指数
1
解决办法
2727
查看次数

如何在 Rust 中将参数传递给线程?

我有一个无法更改的闭包,我需要在新线程中运行它并且需要向其传递一个变量。这就是我想象的代码的样子:

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 中是否可行,如果可以,那么如何实现。

先感谢您。

multithreading closures rust

2
推荐指数
1
解决办法
883
查看次数