当前位置:网站首页>Component based learning (3) path and group annotations in arouter
Component based learning (3) path and group annotations in arouter
2022-04-23 07:12:00 【Drink dichlorvos alone】
It's not right here ARouter A comprehensive analysis of , But the Group and Path Abstract your thoughts to understand
1. introduce Group and Path
I also mentioned in the last article ,Group
It's the group ,Path
Is the specific class in the group . stay ARouter
Of api Module , Targeted Group
and Path
The interface of ARouterGroup
and ARouterPath
. as follows ( Here's just an example , There is not necessarily an interface with the same name , But the mind is the same )
public interface ARouterGroup {
Map<String, Class<? extends ARouterPath>> getGroupMap();
}
ARouterGroup
Interface :
There is oneMap
aggregate ,key
, Is the name of each group , such asapp
,common
wait .value
Is the detail class corresponding to each group name . In fact, it is realizedARouterPath
The class of the interface .ARouterPath
Interface :
public interface ARouterPath {
Map<String, RouterBean> getPathMap();
}
there key
Namely Path
,value
Even with Path
Corresponding , By RouterBean
Encapsulated class
object . such as key
yes /app/MainActivity
,value
Namely RouterBean<MainActivity.class>
RouterBean
That's it , Which is framed Class object . It can be understood that pairs Class Encapsulation of objects
2.Path and Group How it works
Be careful : To have a first Path
The interface of ARouterPath
, There's more Group
The interface of ARouterGroup
, because Group
To traverse, use Path
Speaking of this , Maybe it's still right ARouterGroup
Interface ,ARouterPath
Not familiar with the interface . I'm here to bring the concrete effect , It's easy to understand
When implementing , It is using JavaPoet When generating class files
① First generate , Realized ARouterPath
The class of the interface . Different group
There are different implementation classes . such as app The group corresponds to one ARouterPath
Implementation class of , There's one in there, too Map aggregate ,key
It can be app
All in the group Path
,value
Even with Path
Corresponding RouterBean
.
② Then generate and implement ARouterGroup
The class of the interface . This class is also a group corresponding to one , It is equivalent to a module corresponding to a routing table .key
Just different groups ,value
That's what different groups correspond to ARouterPath
Implementation class of .
If there are only two business modules at present , namely order and personal, be
① Implementation of generation ARouterPath
The specific code implementation of the interface class is shown in the figure
order
Module generated , InsideMap
The collection is stored order All modules path
personal
Module generated
② Implementation of generation ARouterGroup
The specific code implementation of the interface class is shown in the figure
order
Plate generated , It stores the corresponding implementation of all possible modulesARouterPath
Of Class objectpersonal
Plate generated
ARouterManager
Is a global , It's used to cache ARouter$$Group
and ARouter$$Path
Of
When communication is needed , such as order
Module to personal
Module communication , I think we need to find the overall situation ARouterManager
Is there a cache in it ARouter$$Group$$personal
, If there is , Just use the cache directly ARouter$$Group$$personal
, find ARouter$$Path$$personal.class
, And then get the target class RouterBean
object , That is, we get the of the target class class
object , communicate , without , Just compile the generated ARouter$$Group$$personal
Classes and ARouter$$Path$$personal
Add to ARouterManager
Inside ( namely Lazy loading ), Then complete the jump
The code description is like this :
ARouter$$Group$$personal.getGroupMap().get("personal").get("targetClass")
ARouter Parameter transfer of , It's a similar idea , and ButterKnife It's very similar . Is to annotate the parameter definition to be passed , Then, when compiling, generate the class file of a specific class , The purpose of this class file is to use Bundle
, Assign values to these parameters of the corresponding class
What I understand Path and Group That's how it works . The specific method of generating these class files JavaPoet Code , I haven't studied in detail yet , Learn when you need it later , Now master your thoughts .
版权声明
本文为[Drink dichlorvos alone]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230606380247.html
边栏推荐
猜你喜欢
随机推荐
JS 比较2个数组中不同的元素
Tiny4412 HDMI显示
杂七杂八的学习
【机器学习】笔记 4、KNN+交叉验证
去掉状态栏
组件化学习(3)ARouter中的Path和Group注解
JNI中使用open打开文件是返回-1问题
DCMTK(DCM4CHE)与DICOOGLE协同工作
统一任务分发调度执行框架
MySQL笔记4_主键自增长(auto_increment)
Apprentissage par composantes
个人博客网站搭建
iTOP4412内核反复重启
[多屏互动] 实现双多屏异显二:startActivity方式
从0开始封装一套项目的网络请求框架
数据库的事务
launcher隐藏不需要显示的app icon
Itop4412 cannot display boot animation (4.0.3_r1)
Abnormal record-19
组件化学习(1)思想及实现方式