feat: 对齐常驻商城与七鱼客服交互
- 同步商城 H5 登录态与原生 token - 完善商城/原生 tab 切换、动画及返回交互 - 修复七鱼客服键盘避让和状态栏恢复 - 调整开屏跳过按钮与登录入口交互
This commit is contained in:
1 parent
b4343ea528
commit
3b089e2205
37 files changed
+2970
-375
No files matched your search
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
enum MallBridgeTab { home, market, orders, profile }
|
||||
|
||||
class MallBridgeState {
|
||||
const MallBridgeState({
|
||||
this.ready = false,
|
||||
this.activeTab = MallBridgeTab.home,
|
||||
this.canGoBack = false,
|
||||
});
|
||||
|
||||
final bool ready;
|
||||
final MallBridgeTab activeTab;
|
||||
final bool canGoBack;
|
||||
}
|
||||
|
||||
class MallBridgeController {
|
||||
MallBridgeController._();
|
||||
|
||||
static final instance = MallBridgeController._();
|
||||
|
||||
final state = ValueNotifier(const MallBridgeState());
|
||||
Future<void> Function(MallBridgeTab tab, bool reselect)? _activateTab;
|
||||
Future<void> Function()? _goBack;
|
||||
|
||||
void attach({
|
||||
required Future<void> Function(MallBridgeTab tab, bool reselect)
|
||||
activateTab,
|
||||
required Future<void> Function() goBack,
|
||||
}) {
|
||||
_activateTab = activateTab;
|
||||
_goBack = goBack;
|
||||
}
|
||||
|
||||
void detach() {
|
||||
_activateTab = null;
|
||||
_goBack = null;
|
||||
state.value = const MallBridgeState();
|
||||
}
|
||||
|
||||
void update(Map<dynamic, dynamic>? raw) {
|
||||
final tab = MallBridgeTab.values.firstWhere(
|
||||
(item) => item.name == raw?['activeTab'],
|
||||
orElse: () => MallBridgeTab.home,
|
||||
);
|
||||
state.value = MallBridgeState(
|
||||
ready: _asBool(raw?['ready']),
|
||||
activeTab: tab,
|
||||
canGoBack: _asBool(raw?['canGoBack']),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> activate(MallBridgeTab tab, {bool reselect = false}) async {
|
||||
final current = state.value;
|
||||
state.value = MallBridgeState(
|
||||
ready: current.ready,
|
||||
activeTab: tab,
|
||||
canGoBack: current.canGoBack,
|
||||
);
|
||||
await _activateTab?.call(tab, reselect);
|
||||
}
|
||||
|
||||
Future<void> goBack() async => await _goBack?.call();
|
||||
}
|
||||
|
||||
bool _asBool(Object? value) =>
|
||||
value == true || value == 1 || value == '1' || value == 'true';
|
||||
Reference in new issue
Block a user