22
22
import tal .com .d_stack .observer .DStackLifecycleObserver ;
23
23
import tal .com .d_stack .observer .FilterActivityManager ;
24
24
import tal .com .d_stack .router .INativeRouter ;
25
+ import tal .com .d_stack .router .INodeOperation ;
25
26
import tal .com .d_stack .utils .DLog ;
26
27
27
28
/**
@@ -56,6 +57,10 @@ public static DStack getInstance() {
56
57
57
58
private INativeRouter nativeRouter ;
58
59
60
+ private INodeOperation nodeOperation ;
61
+
62
+ private boolean openNodeOperation ;
63
+
59
64
/**
60
65
* 初始化DStack
61
66
*
@@ -136,13 +141,21 @@ public INativeRouter getNativeRouter() {
136
141
*/
137
142
public void pushFlutterPage (String pageRouter , Map <String , Object > params , Class <?> containerCls ) {
138
143
DLog .logD ("要打开的flutter页面路由是:" + pageRouter );
139
- DNode node = DNodeManager .getInstance ().createNode (
140
- pageRouter ,
141
- DStackActivityManager .getInstance ().generateUniqueId (),
142
- DNodePageType .DNodePageTypeFlutter ,
143
- DNodeActionType .DNodeActionTypePush ,
144
- params ,
145
- false );
144
+ DNode node = new DNode .Builder ()
145
+ .target (pageRouter )
146
+ .params (params )
147
+ .pageType (DNodePageType .DNodePageTypeFlutter )
148
+ .action (DNodeActionType .DNodeActionTypePush )
149
+ .boundary (true )
150
+ .build ();
151
+
152
+ if (!DStack .getInstance ().isFlutterApp ()) {
153
+ //原生工程
154
+ if (!DStackActivityManager .getInstance ().haveFlutterContainer ()) {
155
+ //第一次打开flutter页面,设置flutter页面的homepage为true
156
+ node .setHomePage (true );
157
+ }
158
+ }
146
159
147
160
// 如果连续打开同一个Flutter控制器,则做个判断,只打开一次activity
148
161
boolean isSameActivity = DStackActivityManager .getInstance ().isSameActivity (containerCls );
@@ -157,18 +170,32 @@ public void pushFlutterPage(String pageRouter, Map<String, Object> params, Class
157
170
}
158
171
159
172
/**
160
- * native侧关闭flutter页面
173
+ * native侧关闭当前页面,暂时只处理关闭flutter页面
161
174
*/
162
- public void popFlutterPage (String pageRouter , Map <String , Object > params ) {
163
- DLog .logE ("要关闭的flutter页面路由是:" + pageRouter );
164
- DNode node = DNodeManager .getInstance ().createNode (
165
- pageRouter ,
166
- "" ,
167
- DNodePageType .DNodePageTypeFlutter ,
168
- DNodeActionType .DNodeActionTypePop ,
169
- params ,
170
- false );
171
- DNodeManager .getInstance ().checkNode (node );
175
+ public void pop () {
176
+ DNode currentNode = DNodeManager .getInstance ().getCurrentNode ();
177
+ if (currentNode .getPageType ().equals (DNodePageType .DNodePageTypeFlutter )) {
178
+ DNode node = new DNode .Builder ().target (currentNode .getTarget ())
179
+ .pageType (DNodePageType .DNodePageTypeFlutter )
180
+ .action (DNodeActionType .DNodeActionTypePop )
181
+ .isHomePage (currentNode .isHomePage ()).build ();
182
+ DNodeManager .getInstance ().checkNode (node );
183
+ }
184
+ }
185
+
186
+ /**
187
+ * native侧关闭当前页面,暂时只处理关闭flutter页面,带参数
188
+ */
189
+ public void pop (Map <String , Object > params ) {
190
+ DNode currentNode = DNodeManager .getInstance ().getCurrentNode ();
191
+ if (currentNode .getPageType ().equals (DNodePageType .DNodePageTypeFlutter )) {
192
+ DNode node = new DNode .Builder ().target (currentNode .getTarget ())
193
+ .pageType (DNodePageType .DNodePageTypeFlutter )
194
+ .action (DNodeActionType .DNodeActionTypePop )
195
+ .params (params )
196
+ .isHomePage (currentNode .isHomePage ()).build ();
197
+ DNodeManager .getInstance ().checkNode (node );
198
+ }
172
199
}
173
200
174
201
/**
@@ -188,20 +215,23 @@ public void popTo(String pageRouter, Map<String, Object> params) {
188
215
* 返回根页面
189
216
*/
190
217
public void popToRoot () {
191
- DNode rootNode = DNodeManager .getInstance ().createNode (""
192
- , "" , "" , DNodeActionType .DNodeActionTypePopToRoot
193
- , null , false );
194
- DNodeManager .getInstance ().checkNode (rootNode );
218
+ DNode node = new DNode .Builder ()
219
+ .target ("/" )
220
+ .action (DNodeActionType .DNodeActionTypePopToRoot )
221
+ .build ();
222
+ DNodeManager .getInstance ().checkNode (node );
195
223
}
196
224
197
225
/**
198
226
* 返回根页面,带参数
199
227
*/
200
228
public void popToRoot (Map <String , Object > params ) {
201
- DNode rootNode = DNodeManager .getInstance ().createNode (""
202
- , "" , "" , DNodeActionType .DNodeActionTypePopToRoot
203
- , params , false );
204
- DNodeManager .getInstance ().checkNode (rootNode );
229
+ DNode node = new DNode .Builder ()
230
+ .target ("/" )
231
+ .action (DNodeActionType .DNodeActionTypePopToRoot )
232
+ .params (params )
233
+ .build ();
234
+ DNodeManager .getInstance ().checkNode (node );
205
235
}
206
236
207
237
/**
@@ -214,8 +244,6 @@ public boolean isFlutterApp() {
214
244
/**
215
245
* 添加过滤器
216
246
* 某些功能性Activity,不需要做节点管理的,添加至过滤
217
- *
218
- * @param filterString 过滤字符串
219
247
*/
220
248
public void addFilter (String filterString ) {
221
249
if (TextUtils .isEmpty (filterString )) {
@@ -226,13 +254,47 @@ public void addFilter(String filterString) {
226
254
227
255
/**
228
256
* 移除已添加的过滤器
229
- *
230
- * @param filterString
231
257
*/
232
258
public void removeFilter (String filterString ) {
233
259
if (TextUtils .isEmpty (filterString )) {
234
260
return ;
235
261
}
236
262
FilterActivityManager .getInstance ().removeFilter (filterString );
237
263
}
264
+
265
+ /**
266
+ * 在FlutterActivity的onBackPressed()方法内调用
267
+ * 监听flutter控制器的返回键,处理多个flutter控制器,根节点无法返回的问题
268
+ */
269
+ public void listenBackPressed () {
270
+
271
+ }
272
+
273
+ /**
274
+ * 设置节点操作监听
275
+ */
276
+ public void setNodeOperation (INodeOperation nodeOperation ) {
277
+ this .nodeOperation = nodeOperation ;
278
+ }
279
+
280
+ /**
281
+ * 获取节点操作监听
282
+ */
283
+ public INodeOperation getNodeOperation () {
284
+ return nodeOperation ;
285
+ }
286
+
287
+ /**
288
+ * 节点操作是否开启
289
+ */
290
+ public boolean isOpenNodeOperation () {
291
+ return openNodeOperation ;
292
+ }
293
+
294
+ /**
295
+ * 设置是否开启节点操作
296
+ */
297
+ public void setOpenNodeOperation (boolean openNodeOperation ) {
298
+ this .openNodeOperation = openNodeOperation ;
299
+ }
238
300
}
0 commit comments