BaseApplication
最低版本: 2.0.0最后更新: 2021/2/3OPK 入口组件基类,封装了基本的路由处理功能,和对 deeplink 的拦截和处理功能。
支持平台:
平台 | 是否支持 |
豹小秘 | 否 |
豹大/花瓶 | 否 |
豹小秘 Mini | 是 |
方法
方法名 | 参数 | JS类型 | 必填 | 参数说明 | 方法说明 | 最低版本 |
onTriggerByIFTTT | ecaInfo | ECAGroupRules | yes | ifttt 启动信息 | 当opk被ifttt类型的deeplink触发时,该方法会被回调 | 2.0.0 |
registerDeepLinkInterceptor | interceptor | DeepLinkInterceptor | yes | deep link拦截器 | 注册deep link的拦截器 | 2.0.0 |
afterStartByDeepLink | path | string | yes | 要切换到的path | 冷启动 | 2.0.0 |
query | any | yes | 启动 opk 指令信息 | |||
afterRecoveryByDeepLink | path | string | yes | 要切换到的path | 从suspend切到运行状态 | 2.0.0 |
query | any | yes | 恢复 opk 指令信息 | |||
afterNewDeepLink | path | string | yes | 要切换到的path | OPK 在前台的时候,收到DeepLink | 2.0.0 |
query | any | yes | 指令信息 | |||
notifyUpdateActiveAbility | 无 | 无 | 无 | 无 | Mini toC 上用于通知 global 更新主动能力,默认是启用所有主动能力,业务方可重新该方法执行不同的逻辑 | 2.0.0 |
代码示例
@observer
class App extends BaseApplication<BaseApplicationProps> {
public constructor(props: any) {
super(props);
this.initDeepLink();
}
private initDeepLink(): void {
const handleDeepLink = (path: string, query: any = {}): boolean => {
console.log(TAG, 'query:' + JSON.stringify(query));
if (path === '/alarmlist') {
speechApi.queryByText('查看闹钟');
return true;
} else if (path === '/follow') {
if (!ActiveAbilityController.isBodyFollowEnable()) {
ActiveAbilityController.setBodyFollowEnable(true);
}
return true;
} else if (query.asrShow !== undefined) {
if (query.asrShow === 'false') {
globalASRModel.setVisible(false);
}
return true;
}
return false;
};
const skillInterceptor: DeepLinkInterceptor = {
intercept(path: string, query: any): OpenDeepLinkInfo | undefined {
if (handleDeepLink(path, query)) {
return undefined;
} else {
return { path, query };
}
}
};
this.registerDeepLinkInterceptor(skillInterceptor);
}
public componentWillMount(): void {
console.log(TAG, 'componentWillMount');
}
public componentDidMount(): void {
super.componentDidMount();
console.log(
TAG,
'componentDidMount'
);
}
public componentWillUnmount(): void {
super.componentWillUnmount();
console.log(TAG, 'componentWillUnmount');
}
public render(): React.ReactElement {
return (
<View style={styles.container}>
<ViewContainerProvider />
<AppContainer />
</View>
);
}
// 禁用主动能力
public notifyUpdateActiveAbility() {
ActiveAbilityManager.disableAll();
}
}