Skip to content

Commit a5f2be5

Browse files
committed
feat(roomplan): add error callback
1 parent 5ec96f0 commit a5f2be5

File tree

6 files changed

+33
-14
lines changed

6 files changed

+33
-14
lines changed

apps/demo/src/modals/modal-roomplan.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ export function shownModally(args: EventData) {
1010
let roomCaptureView: RoomCaptureView;
1111

1212
export function loadedRoomCaptureView(args) {
13-
console.log('loadedRoomCaptureView!');
1413
roomCaptureView = args.object;
15-
console.log('roomCaptureView.start:', roomCaptureView.start);
1614
}
1715

1816
export class RoomPlanModel extends Observable {
@@ -26,6 +24,16 @@ export class RoomPlanModel extends Observable {
2624
this.page.closeModal();
2725
}
2826

27+
done() {
28+
if (this.scanning) {
29+
this.scanning = false;
30+
this.notifyPropertyChange('scanning', this.scanning);
31+
roomCaptureView.stop();
32+
} else {
33+
this.save();
34+
}
35+
}
36+
2937
save() {
3038
Dialogs.prompt({
3139
title: 'Save 3D Room Model?',
@@ -35,6 +43,10 @@ export class RoomPlanModel extends Observable {
3543
cancelButtonText: 'Cancel',
3644
}).then((value) => {
3745
if (value.result && value.text) {
46+
const filePath = path.join(knownFolders.documents().path, `${value.text}.usdz`);
47+
roomCaptureView.export(filePath, (outputPath) => {
48+
this.page.closeModal(outputPath);
49+
});
3850
} else {
3951
this.page.closeModal();
4052
}

apps/demo/src/modals/modal-roomplan.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<GridLayout rows="*" columns="*">
33
<rp:RoomCaptureView width="100%" height="100%" loaded="loadedRoomCaptureView" iosOverflowSafeArea="true"/>
44
<GridLayout rows="auto" columns="20,auto,*,auto,20" verticalAlignment="top" marginTop="20">
5-
<Button col="1" text="Cancel" tap="{{cancel}}" fontSize="16" color="white" visibility="{{ scanning ? 'visible' : 'collapsed' }}"/>
5+
<Button col="1" text="Cancel" tap="{{cancel}}" fontSize="16" color="white" color="{{scanning ? 'white' : '#5fb9f9'}}"/>
66
<Button col="3" text="{{scanning ? 'Done' : 'Save' }}" tap="{{done}}" fontSize="16" color="{{scanning ? 'white' : '#5fb9f9'}}" />
77
</GridLayout>
88
</GridLayout>

apps/demo/src/plugin-demos/roomplan.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ export class DemoModel extends DemoSharedRoomplan {
1919
enablePreview: true,
2020
},
2121
closeCallback: (savedModelPath: string) => {
22-
console.log('savedModelPath:', savedModelPath);
23-
setTimeout(() => {
24-
Dialogs.alert({
25-
title: 'Model saved!',
26-
message: savedModelPath,
27-
okButtonText: 'Ok',
28-
});
29-
}, 1000);
22+
if (savedModelPath) {
23+
console.log('savedModelPath:', savedModelPath);
24+
setTimeout(() => {
25+
Dialogs.alert({
26+
title: 'Model saved!',
27+
message: savedModelPath,
28+
okButtonText: 'Ok',
29+
});
30+
}, 1000);
31+
}
3032
},
3133
});
3234
}

packages/roomplan/index.ios.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export class RoomCaptureView extends RoomCaptureViewCommon {
1717
}
1818

1919
export(filePath: string, callback?: (outputPath: string) => void) {
20-
this.roomPlan.exportResultsWithFilePathCallback(filePath, callback);
20+
this.roomPlan.exportResultsWithFilePathCallbackErrorCallback(filePath, callback, (error) => {
21+
console.error('error:', error);
22+
});
2123
}
2224
}

packages/roomplan/platforms/ios/src/NSCRoomPlan.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import RoomPlan
4949
finalResults = processedResult
5050
}
5151

52-
@objc public func exportResults(filePath: String? = nil, callback: ((_ destinationPath: String?) -> ())? = nil) {
52+
@objc public func exportResults(filePath: String? = nil, callback: ((_ destinationPath: String?) -> ())? = nil, errorCallback: ((_ error: String?) -> ())? = nil) {
5353
let destinationURL = filePath != nil ? URL(fileURLWithPath: filePath!) : FileManager.default.temporaryDirectory.appending(path: "Room.usdz")
5454
do {
5555
try finalResults?.export(to: destinationURL)
@@ -60,6 +60,9 @@ import RoomPlan
6060

6161
} catch {
6262
print("Error = \(error)")
63+
if (errorCallback != nil) {
64+
errorCallback!("Export error: \(error.localizedDescription)")
65+
}
6366
}
6467
}
6568
}

packages/roomplan/typings/objc!NSCRoomPlan.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ declare class NSCRoomPlan extends UIViewController {
33

44
static new(): NSCRoomPlan; // inherited from NSObject
55

6-
exportResultsWithFilePathCallback(filePath: string, callback: (p1: string) => void): void;
6+
exportResultsWithFilePathCallbackErrorCallback(filePath: string, callback: (p1: string) => void, errorCallback: (p1: string) => void): void;
77

88
startSession(): void;
99

0 commit comments

Comments
 (0)