Skip to content

Commit 3fdcb5f

Browse files
authored
Merge pull request #180 from jw2175/backto
Backto bug fixes: namepsace error on base class, json merging bug
2 parents 97f1797 + 35b44b6 commit 3fdcb5f

5 files changed

Lines changed: 73 additions & 19 deletions

File tree

ios/ElectrodeApiImpl.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
6E948F122602991F00E99E37 /* MiniAppNavViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E948EEA2602991F00E99E37 /* MiniAppNavViewController.swift */; };
4747
6E948F132602991F00E99E37 /* RequestHandlerProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E948EEB2602991F00E99E37 /* RequestHandlerProvider.swift */; };
4848
6E948F142602991F00E99E37 /* RequestHandlerConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E948EEC2602991F00E99E37 /* RequestHandlerConfig.swift */; };
49+
6EA337DB263CC60C00612B5B /* ENNavigationUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EA337C1263CC60C00612B5B /* ENNavigationUtils.swift */; };
4950
6ED8270723D7C2EC00A0CEE9 /* EnNavigationEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ED8270023D7C2EC00A0CEE9 /* EnNavigationEvents.swift */; };
5051
6ED8270823D7C2EC00A0CEE9 /* NavigationBarButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ED8270123D7C2EC00A0CEE9 /* NavigationBarButton.swift */; };
5152
6ED8270923D7C2EC00A0CEE9 /* NavigationBarLeftButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ED8270223D7C2EC00A0CEE9 /* NavigationBarLeftButton.swift */; };
@@ -503,6 +504,7 @@
503504
6E948EEA2602991F00E99E37 /* MiniAppNavViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MiniAppNavViewController.swift; sourceTree = "<group>"; };
504505
6E948EEB2602991F00E99E37 /* RequestHandlerProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestHandlerProvider.swift; sourceTree = "<group>"; };
505506
6E948EEC2602991F00E99E37 /* RequestHandlerConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestHandlerConfig.swift; sourceTree = "<group>"; };
507+
6EA337C1263CC60C00612B5B /* ENNavigationUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ENNavigationUtils.swift; sourceTree = "<group>"; };
506508
6ED8270023D7C2EC00A0CEE9 /* EnNavigationEvents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EnNavigationEvents.swift; path = container/ElectrodeContainer/APIs/EnNavigationEvents.swift; sourceTree = SOURCE_ROOT; };
507509
6ED8270123D7C2EC00A0CEE9 /* NavigationBarButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NavigationBarButton.swift; path = container/ElectrodeContainer/APIs/NavigationBarButton.swift; sourceTree = SOURCE_ROOT; };
508510
6ED8270223D7C2EC00A0CEE9 /* NavigationBarLeftButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NavigationBarLeftButton.swift; path = container/ElectrodeContainer/APIs/NavigationBarLeftButton.swift; sourceTree = SOURCE_ROOT; };
@@ -760,6 +762,7 @@
760762
6E948EE42602991F00E99E37 /* ENNavigationBarState.swift */,
761763
6E948EE32602991F00E99E37 /* ENNavigationDelegate.swift */,
762764
6E948EE72602991F00E99E37 /* ENNavigationProtocol.swift */,
765+
6EA337C1263CC60C00612B5B /* ENNavigationUtils.swift */,
763766
6E948EE62602991F00E99E37 /* ENOverlayProtocol.swift */,
764767
6E948EEA2602991F00E99E37 /* MiniAppNavViewController.swift */,
765768
);
@@ -1388,6 +1391,7 @@
13881391
6ED8270723D7C2EC00A0CEE9 /* EnNavigationEvents.swift in Sources */,
13891392
49398F13519C493BAB5B79AF /* Processor.swift in Sources */,
13901393
82CBA81827F6428C840A8210 /* None.swift in Sources */,
1394+
6EA337DB263CC60C00612B5B /* ENNavigationUtils.swift in Sources */,
13911395
96984CA17C8F4B5B962D5E78 /* ElectrodeBridgeEvent.m in Sources */,
13921396
6E948F0D2602991F00E99E37 /* ENNavigationAPIImpl.swift in Sources */,
13931397
A19374775C014A0F8683C6CA /* ElectrodeBridgeFailureMessage.m in Sources */,

ios/ElectrodeApiImpl/APIImpls/Core/ENCoreDelegate.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,22 @@ import UIKit
7777
guard let dict2 = dictionary2 else {
7878
return dictionary1
7979
}
80-
return dict2.merging(dict1) {(current, _) in current }
80+
81+
var result = dict2.merging(dict1) {(current, _) in current }
82+
83+
/* When both dictionaries have jsonPayloads,
84+
Convert the json strings to dictionaries,
85+
Merge and convert back to json strings
86+
Set back to "jsonPayload" key
87+
*/
88+
if let payload1 = dict1["jsonPayload"] as? String, let payload2 = dict2["jsonPayload"] as? String {
89+
if let jsonDict1 = payload1.convertStringToDict(), let jsonDict2 = payload2.convertStringToDict() {
90+
let jsonResult = jsonDict2.merging(jsonDict1) {(current, _) in current }
91+
let jsonString = ENNavigationUtils.jsonToString(json: jsonResult)
92+
result["jsonPayload"] = jsonString
93+
}
94+
}
95+
return result
8196
}
8297

8398
func deinitRNView() {

ios/ElectrodeApiImpl/APIImpls/Navigation/ENBaseNavigationController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ open class ENBaseNavigationController: UINavigationController, ENMiniAppNavDataP
2626
return false
2727
}
2828
open var finish: Payload?
29-
open var backToMiniApp: BackToRoute = { _, _ in
29+
open var backTo: BackToRoute = { _, _ in
3030
return false
3131
}
3232

@@ -42,7 +42,7 @@ open class ENBaseNavigationController: UINavigationController, ENMiniAppNavDataP
4242
self.finish = { payload in
4343
self.finishFlow(payload)
4444
}
45-
self.backToMiniApp = { componentName, backProperties in
45+
self.backTo = { componentName, backProperties in
4646
return self.backToMiniApp(componentName, backProperties)
4747
}
4848
}

ios/ElectrodeApiImpl/APIImpls/Navigation/ENNavigationDelegate.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -476,19 +476,3 @@ import UIKit
476476
return "{\"id\": \"" + buttonId + "\"}"
477477
}
478478
}
479-
480-
extension String {
481-
func convertStringToDict() -> [AnyHashable: Any]? {
482-
do {
483-
if let data = self.data(using: String.Encoding.utf8), let dict = try JSONSerialization.jsonObject(with: data, options: [.allowFragments]) as? [AnyHashable: Any] {
484-
return dict
485-
} else {
486-
return nil
487-
}
488-
} catch let error as NSError {
489-
let logger = ElectrodeConsoleLogger.sharedInstance()
490-
logger.log(.error, message: error.description)
491-
}
492-
return nil
493-
}
494-
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2021 Walmart Labs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import Foundation
18+
19+
class ENNavigationUtils {
20+
21+
static func jsonToString(json: [AnyHashable: Any]) -> String {
22+
do {
23+
let data1 = try JSONSerialization.data(withJSONObject: json, options: JSONSerialization.WritingOptions.fragmentsAllowed) // first of all convert json to the data
24+
let convertedString = String(data: data1, encoding: String.Encoding.utf8) // the data will be converted to the string
25+
return convertedString ?? ""
26+
} catch let error as NSError {
27+
let logger = ElectrodeConsoleLogger.sharedInstance()
28+
logger.log(.error, message: error.description)
29+
}
30+
return ""
31+
}
32+
33+
}
34+
35+
extension String {
36+
37+
func convertStringToDict() -> [AnyHashable: Any]? {
38+
do {
39+
if let data = self.data(using: String.Encoding.utf8), let dict = try JSONSerialization.jsonObject(with: data, options: [.allowFragments]) as? [AnyHashable: Any] {
40+
return dict
41+
} else {
42+
return nil
43+
}
44+
} catch let error as NSError {
45+
let logger = ElectrodeConsoleLogger.sharedInstance()
46+
logger.log(.error, message: error.description)
47+
}
48+
return nil
49+
}
50+
51+
}

0 commit comments

Comments
 (0)