Skip to content

Commit 9cfcbbd

Browse files
author
maxu
committed
修改混合栈逻辑
1 parent 1835cad commit 9cfcbbd

File tree

8 files changed

+71
-23
lines changed

8 files changed

+71
-23
lines changed

android/src/main/kotlin/tal/com/d_stack/action/DActionManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ private static void enterPageWithNode(DNode node, String action, boolean animate
9393
// 打开flutter页面
9494
// 给当前flutter节点设置对应的activity
9595
DNode currentNode = DNodeManager.getInstance().getCurrentNode();
96-
currentNode.setUniqueId(DStackUtils.generateUniqueId());
9796
currentNode.setActivity(new WeakReference(DStackActivityManager.getInstance().getTopActivity()));
9897
}
9998
} else {
@@ -140,7 +139,7 @@ private static void closePageWithNodes(List<DNode> nodes, final String action, f
140139
flutterNodes.add(nodeResponse.toMap());
141140
}
142141
} else {
143-
nativeNodes.add(loopNode.getUniqueId());
142+
nativeNodes.add(loopNode.getIdentifier());
144143
}
145144
}
146145
//处理需要关闭的控制器

android/src/main/kotlin/tal/com/d_stack/action/DOperationManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/**
1212
* 节点操作行为记录
13-
*/
13+
*/
1414
public class DOperationManager {
1515
public static void operation(DNode node) {
1616
if (!DStack.getInstance().isOpenNodeOperation()) {

android/src/main/kotlin/tal/com/d_stack/channel/DStackMethodHandler.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package tal.com.d_stack.channel;
22

33

4+
import android.util.Log;
5+
6+
import org.json.JSONObject;
7+
48
import java.util.ArrayList;
59
import java.util.HashMap;
610
import java.util.List;
@@ -13,6 +17,7 @@
1317
import tal.com.d_stack.node.DNode;
1418
import tal.com.d_stack.node.DNodeManager;
1519
import tal.com.d_stack.node.DNodeResponse;
20+
import tal.com.d_stack.utils.DLog;
1621

1722
/**
1823
* 框架消息通道
@@ -47,6 +52,9 @@ public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
4752
private static void handleSendNodeToNative(Map<String, Object> args) {
4853
DNode node = createNodeFromFlutter(args);
4954
if (node != null) {
55+
DLog.logD("----------接收handleSendNodeToNative消息----------");
56+
DLog.logD(node.toString());
57+
DLog.logD("----------接收handleSendNodeToNative消息----------");
5058
DNodeManager.getInstance().checkNode(node);
5159
}
5260
}
@@ -57,6 +65,9 @@ private static void handleSendNodeToNative(Map<String, Object> args) {
5765
private static void handleSendRemoveFlutterPageNode(Map<String, Object> args) {
5866
DNode node = createNodeFromFlutter(args);
5967
if (node != null) {
68+
DLog.logD("----------接收handleSendRemoveFlutterPageNode消息----------");
69+
DLog.logD(node.toString());
70+
DLog.logD("----------接收handleSendRemoveFlutterPageNode消息----------");
6071
DNodeManager.getInstance().handleNeedRemoveFlutterNode(node);
6172
}
6273
}
@@ -102,6 +113,10 @@ public void notImplemented() {
102113

103114
}
104115
});
116+
DLog.logD("----------发送sendNode消息----------");
117+
JSONObject jsonObject = new JSONObject(resultMap);
118+
DLog.logD(jsonObject.toString());
119+
DLog.logD("----------发送sendNode消息----------");
105120
}
106121

107122
/**
@@ -130,6 +145,10 @@ public void notImplemented() {
130145

131146
}
132147
});
148+
DLog.logD("----------发送sendNode消息----------");
149+
JSONObject jsonObject = new JSONObject(resultMap);
150+
DLog.logD(jsonObject.toString());
151+
DLog.logD("----------发送sendNode消息----------");
133152
}
134153

135154

@@ -203,6 +222,7 @@ public static void sendNodeOperation(DNodeResponse nodeResponse) {
203222
resultMap.put("homePage", nodeResponse.homePage);
204223
resultMap.put("boundary", nodeResponse.boundary);
205224
resultMap.put("animated", nodeResponse.animated);
225+
resultMap.put("identifier", nodeResponse.identifier);
206226
DStack.getInstance().getMethodChannel().invokeMethod("sendOperationNodeToFlutter", resultMap, new MethodChannel.Result() {
207227
@Override
208228
public void success(Object result) {
@@ -234,6 +254,7 @@ public static DNode createNodeFromFlutter(Map<String, Object> args) {
234254
Map<String, Object> params = new HashMap<>();
235255
boolean homePage = false;
236256
boolean animated = false;
257+
String identifier = "";
237258
if (args.get("target") != null) {
238259
target = (String) args.get("target");
239260
}
@@ -252,6 +273,9 @@ public static DNode createNodeFromFlutter(Map<String, Object> args) {
252273
if (args.get("animated") != null) {
253274
animated = (boolean) args.get("animated");
254275
}
276+
if (args.get("identifier") != null) {
277+
identifier = (String) args.get("identifier");
278+
}
255279
//创建Node节点信息
256280
DNode node = new DNode.Builder()
257281
.target(target)
@@ -260,6 +284,7 @@ public static DNode createNodeFromFlutter(Map<String, Object> args) {
260284
.params(params)
261285
.isHomePage(homePage)
262286
.animated(animated)
287+
.identifier(identifier)
263288
.fromFlutter(true)
264289
.build();
265290
return node;

android/src/main/kotlin/tal/com/d_stack/node/DNode.java

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ public class DNode {
2121
// flutter页面时,是route,native唯一id
2222
private String target;
2323

24-
//native页面的唯一id
25-
private String uniqueId;
26-
2724
// 附带参数
2825
private Map<String, Object> params;
2926

@@ -48,6 +45,9 @@ public class DNode {
4845
//是否开启转场动画
4946
private boolean animated;
5047

48+
//页面唯一标识
49+
private String identifier;
50+
5151
public DNode(Builder builder) {
5252
this.action = builder.action;
5353
this.pageType = builder.pageType;
@@ -60,7 +60,15 @@ public DNode(Builder builder) {
6060
this.activity = builder.activity;
6161
this.popTo = builder.popTo;
6262
this.rootPage = builder.rootPage;
63-
this.uniqueId = builder.uniqueId;
63+
this.identifier = builder.identifier;
64+
}
65+
66+
public String getIdentifier() {
67+
return identifier;
68+
}
69+
70+
public void setIdentifier(String identifier) {
71+
this.identifier = identifier;
6472
}
6573

6674

@@ -76,7 +84,7 @@ public static class Builder {
7684
private WeakReference<Activity> activity = null;
7785
private boolean popTo = false;
7886
private boolean rootPage = false;
79-
private String uniqueId = "";
87+
private String identifier = "";
8088

8189
public Builder action(String action) {
8290
this.action = action;
@@ -133,8 +141,8 @@ public Builder isRootPage(boolean isRootPage) {
133141
return this;
134142
}
135143

136-
public Builder uniqueId(String uniqueId) {
137-
this.uniqueId = uniqueId;
144+
public Builder identifier(String identifier) {
145+
this.identifier = identifier;
138146
return this;
139147
}
140148

@@ -184,14 +192,6 @@ public void setPageType(String pageType) {
184192
this.pageType = pageType;
185193
}
186194

187-
public String getUniqueId() {
188-
return uniqueId;
189-
}
190-
191-
public void setUniqueId(String uniqueId) {
192-
this.uniqueId = uniqueId;
193-
}
194-
195195
public WeakReference<Activity> getActivity() {
196196
return activity;
197197
}
@@ -239,4 +239,22 @@ public boolean isAnimated() {
239239
public void setAnimated(boolean animated) {
240240
this.animated = animated;
241241
}
242+
243+
@Override
244+
public String toString() {
245+
return "DNode{" +
246+
"action='" + action + '\'' +
247+
", pageType='" + pageType + '\'' +
248+
", target='" + target + '\'' +
249+
", params=" + params + '\'' +
250+
", fromFlutter=" + fromFlutter + '\'' +
251+
", activity=" + activity + '\'' +
252+
", popTo=" + popTo + '\'' +
253+
", homePage=" + homePage + '\'' +
254+
", rootPage=" + rootPage + '\'' +
255+
", boundary=" + boundary + '\'' +
256+
", animated=" + animated + '\'' +
257+
", identifier='" + identifier + '\'' +
258+
'}';
259+
}
242260
}

android/src/main/kotlin/tal/com/d_stack/node/DNodeManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public void checkNode(DNode node) {
8787
node.setPageType(currentNode.getPageType());
8888
node.setHomePage(currentNode.isHomePage());
8989
node.setRootPage(currentNode.isRootPage());
90+
node.setIdentifier(currentNode.getIdentifier());
9091
DActionManager.pop(node);
9192
updateNodes();
9293
} else {
@@ -315,6 +316,7 @@ public void handleNeedRemoveFlutterNode(DNode node) {
315316
if (isCritical) {
316317
//临界状态,当前清除节点flutter,上一个节点native
317318
if (DStackActivityManager.getInstance().isExecuteStack()) {
319+
//正在进行popTo等关闭多个页面操作,直接返回
318320
return;
319321
}
320322
//关闭栈顶flutter控制器
@@ -412,6 +414,7 @@ public DNodeResponse createNodeResponse(DNode node) {
412414
nodeResponse.homePage = node.isHomePage();
413415
nodeResponse.animated = node.isAnimated();
414416
nodeResponse.boundary = node.isBoundary();
417+
nodeResponse.identifier = node.getIdentifier();
415418
return nodeResponse;
416419
}
417420

android/src/main/kotlin/tal/com/d_stack/node/DNodeResponse.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class DNodeResponse {
1414
public boolean homePage = false;
1515
public boolean animated = false;
1616
public boolean boundary = false;
17+
public String identifier = "";
1718

1819
@Override
1920
public String toString() {
@@ -26,6 +27,7 @@ public String toString() {
2627
jo.put("homePage", homePage);
2728
jo.put("animated", animated);
2829
jo.put("boundary", boundary);
30+
jo.put("identifier", identifier);
2931
} catch (JSONException e) {
3032
e.printStackTrace();
3133
}
@@ -41,6 +43,7 @@ public Map<String, Object> toMap() {
4143
map.put("homePage", homePage);
4244
map.put("animated", animated);
4345
map.put("boundary", boundary);
46+
map.put("identifier", identifier);
4447
return map;
4548
}
4649
}

android/src/main/kotlin/tal/com/d_stack/observer/DStackLifecycleObserver.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.lang.ref.WeakReference;
1111

1212
import io.flutter.embedding.android.FlutterView;
13-
import tal.com.d_stack.DStack;
1413
import tal.com.d_stack.lifecycle.PageLifecycleManager;
1514
import tal.com.d_stack.node.DNode;
1615
import tal.com.d_stack.node.DNodeManager;
@@ -49,7 +48,7 @@ public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle saved
4948
.target("/")
5049
.pageType(DNodePageType.DNodePageTypeFlutter)
5150
.action(DNodeActionType.DNodeActionTypePush)
52-
.uniqueId(DStackUtils.generateUniqueId())
51+
.identifier(DStackUtils.generateUniqueId())
5352
.isHomePage(true)
5453
.isRootPage(true)
5554
.build();
@@ -59,7 +58,7 @@ public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle saved
5958
.target("/")
6059
.pageType(DNodePageType.DNodePageTypeNative)
6160
.action(DNodeActionType.DNodeActionTypePush)
62-
.uniqueId(DStackUtils.generateUniqueId())
61+
.identifier(DStackUtils.generateUniqueId())
6362
.isHomePage(true)
6463
.isRootPage(true)
6564
.build();
@@ -73,7 +72,7 @@ public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle saved
7372
.target(activity.getClass().getName())
7473
.pageType(DNodePageType.DNodePageTypeNative)
7574
.action(DNodeActionType.DNodeActionTypePush)
76-
.uniqueId(DStackUtils.generateUniqueId())
75+
.identifier(DStackUtils.generateUniqueId())
7776
.build();
7877
DNodeManager.getInstance().checkNode(node);
7978
}
@@ -149,6 +148,7 @@ public void onActivityDestroyed(@NonNull Activity activity) {
149148
.action(DNodeActionType.DNodeActionTypePop)
150149
.isHomePage(currentNode.isHomePage())
151150
.isRootPage(currentNode.isRootPage())
151+
.identifier(currentNode.getIdentifier())
152152
.isPopTo(isPopTo)
153153
.build();
154154
DNodeManager.getInstance().checkNode(node);

example/android/app/src/main/kotlin/tal/com/d_stack_example/DStackApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ public void onCreate() {
2222
application.startActivity(intent);
2323
}
2424
});
25-
DStack.getInstance().setOpenNodeOperation(true);
25+
DStack.getInstance().setOpenNodeOperation(false);
2626
}
2727
}

0 commit comments

Comments
 (0)