Skip to main content

ActivityManager

Struct ActivityManager 

Source
pub struct ActivityManager<H: ActivityHost> { /* private fields */ }
Expand description

页面堆栈与路由调度器。

负责管理 Activity 的入栈、出栈,协调生命周期方法的调用,并聚合页面切换产生的异步任务。

Implementations§

Source§

impl<H: ActivityHost> ActivityManager<H>

Source

pub fn new<F>(factory: F) -> Self
where F: Fn(&H::Route) -> Box<dyn Activity<H>> + 'static,

创建一个新的 ActivityManager。

factory 是一个闭包,负责根据路由枚举实例化对应的 Activity

Source

pub fn update( &mut self, context: &mut H::Context, message: H::Message, ) -> H::Task

将消息分发给当前处于栈顶的活动页面。

Source

pub fn start_activity( &mut self, context: &mut H::Context, route: H::Route, ) -> H::Task

启动一个新页面,处理路由逻辑及堆栈变化,并返回相关的异步任务。

Source

pub fn back(&mut self, context: &mut H::Context) -> (bool, H::Task)

模拟物理返回键逻辑,弹出栈顶页面。

返回一个元组:

  • bool: 如果成功返回上一页则为 true;如果栈已空或仅剩一页无法返回则为 false
  • H::Task: 退出动作产生的异步任务。
Source

pub fn views<'a>(&'a self, context: &'a H::Context) -> Vec<H::View<'a>>

执行视图构建,利用“画家算法”收集需要渲染的页面。

从栈顶向下查找,直到遇到第一个不透明(is_translucent() == false)的页面为止, 仅收集并返回可见层级的视图。

Source

pub fn stack_len(&self) -> usize

获取当前栈中的页面数量(仅用于测试或状态监控)

Auto Trait Implementations§

§

impl<H> Freeze for ActivityManager<H>

§

impl<H> !RefUnwindSafe for ActivityManager<H>

§

impl<H> !Send for ActivityManager<H>

§

impl<H> !Sync for ActivityManager<H>

§

impl<H> Unpin for ActivityManager<H>

§

impl<H> UnsafeUnpin for ActivityManager<H>

§

impl<H> !UnwindSafe for ActivityManager<H>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.