Skip to content

Commit 6f6d6aa

Browse files
committed
Added review fixes and bug fixes
1 parent 71672a4 commit 6f6d6aa

9 files changed

Lines changed: 61 additions & 60 deletions

File tree

android/src/main/kotlin/com/qonversion/flutter/sdk/qonversion_flutter_sdk/QonversionPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class QonversionPlugin : MethodCallHandler, FlutterPlugin, ActivityAware {
111111
"remoteConfigList" -> {
112112
return remoteConfigList(result)
113113
}
114+
"closeNoCodes" -> noCodesPlugin?.closeNoCodes(result)
114115
}
115116

116117
// Methods with args
@@ -135,7 +136,6 @@ class QonversionPlugin : MethodCallHandler, FlutterPlugin, ActivityAware {
135136
"initializeNoCodes" -> noCodesPlugin?.initializeNoCodes(args["projectKey"] as? String ?: "", result)
136137
"setScreenPresentationConfig" -> noCodesPlugin?.setScreenPresentationConfig(args["config"] as? Map<String, Any>, args["contextKey"] as? String, result)
137138
"showNoCodesScreen" -> noCodesPlugin?.showNoCodesScreen(args["contextKey"] as? String, result)
138-
"closeNoCodes" -> noCodesPlugin?.closeNoCodes(result)
139139
else -> result.notImplemented()
140140
}
141141
}

example/lib/nocodes_view.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class _NoCodesViewState extends State<NoCodesView> {
6060

6161
_screenFailedToLoadStream = NoCodes.getSharedInstance().screenFailedToLoadStream.listen((event) {
6262
_addEvent('Screen Failed to Load: ${event.payload}');
63-
NoCodes.getSharedInstance().close();
63+
// NoCodes.getSharedInstance().close();
6464
});
6565
}
6666

@@ -75,6 +75,15 @@ class _NoCodesViewState extends State<NoCodesView> {
7575

7676
Future<void> _showScreen() async {
7777
try {
78+
// Set presentation style config before showing screen
79+
final config = NoCodesPresentationConfig(
80+
animated: true,
81+
presentationStyle: NoCodesPresentationStyle.push,
82+
);
83+
84+
await NoCodes.getSharedInstance().setScreenPresentationConfig(config, contextKey: 'kamo_test');
85+
_addEvent('Presentation config set');
86+
7887
await NoCodes.getSharedInstance().showScreen('kamo_test');
7988
} catch (e) {
8089
print('Error showing screen: $e');

ios/Classes/NoCodesPlugin.swift

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ import Flutter
1111
import QonversionSandwich
1212

1313
public class NoCodesPlugin: NSObject {
14+
// Event type constants
15+
private let eventScreenShown = "nocodes_screen_shown"
16+
private let eventFinished = "nocodes_finished"
17+
private let eventActionStarted = "nocodes_action_started"
18+
private let eventActionFailed = "nocodes_action_failed"
19+
private let eventActionFinished = "nocodes_action_finished"
20+
private let eventScreenFailedToLoad = "nocodes_screen_failed_to_load"
1421
private var screenShownEventStreamHandler: BaseEventStreamHandler?
1522
private var finishedEventStreamHandler: BaseEventStreamHandler?
1623
private var actionStartedEventStreamHandler: BaseEventStreamHandler?
@@ -22,32 +29,32 @@ public class NoCodesPlugin: NSObject {
2229
public func register(_ registrar: FlutterPluginRegistrar) {
2330

2431
// Register separate event channels for each event type
25-
let screenShownListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: "nocodes_screen_shown")
32+
let screenShownListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: eventScreenShown)
2633
screenShownListener.register() { eventStreamHandler in
2734
self.screenShownEventStreamHandler = eventStreamHandler
2835
}
2936

30-
let finishedListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: "nocodes_finished")
37+
let finishedListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: eventFinished)
3138
finishedListener.register() { eventStreamHandler in
3239
self.finishedEventStreamHandler = eventStreamHandler
3340
}
3441

35-
let actionStartedListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: "nocodes_action_started")
42+
let actionStartedListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: eventActionStarted)
3643
actionStartedListener.register() { eventStreamHandler in
3744
self.actionStartedEventStreamHandler = eventStreamHandler
3845
}
3946

40-
let actionFailedListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: "nocodes_action_failed")
47+
let actionFailedListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: eventActionFailed)
4148
actionFailedListener.register() { eventStreamHandler in
4249
self.actionFailedEventStreamHandler = eventStreamHandler
4350
}
4451

45-
let actionFinishedListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: "nocodes_action_finished")
52+
let actionFinishedListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: eventActionFinished)
4653
actionFinishedListener.register() { eventStreamHandler in
4754
self.actionFinishedEventStreamHandler = eventStreamHandler
4855
}
4956

50-
let screenFailedToLoadListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: "nocodes_screen_failed_to_load")
57+
let screenFailedToLoadListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: eventScreenFailedToLoad)
5158
screenFailedToLoadListener.register() { eventStreamHandler in
5259
self.screenFailedToLoadEventStreamHandler = eventStreamHandler
5360
}
@@ -94,11 +101,6 @@ public class NoCodesPlugin: NSObject {
94101
noCodesSandwich?.close()
95102
result(nil)
96103
}
97-
98-
public func getAvailableEvents(_ result: @escaping FlutterResult) {
99-
let events = noCodesSandwich?.getAvailableEvents() ?? []
100-
result(events)
101-
}
102104
}
103105

104106
extension NoCodesPlugin: NoCodesEventListener {
@@ -117,22 +119,22 @@ extension NoCodesPlugin: NoCodesEventListener {
117119

118120
DispatchQueue.main.async {
119121
switch event {
120-
case "nocodes_screen_shown":
122+
case eventScreenShown:
121123
self.screenShownEventStreamHandler?.eventSink?(jsonString)
122124

123-
case "nocodes_finished":
125+
case eventFinished:
124126
self.finishedEventStreamHandler?.eventSink?(jsonString)
125127

126-
case "nocodes_action_started":
128+
case eventActionStarted:
127129
self.actionStartedEventStreamHandler?.eventSink?(jsonString)
128130

129-
case "nocodes_action_failed":
131+
case eventActionFailed:
130132
self.actionFailedEventStreamHandler?.eventSink?(jsonString)
131133

132-
case "nocodes_action_finished":
134+
case eventActionFinished:
133135
self.actionFinishedEventStreamHandler?.eventSink?(jsonString)
134136

135-
case "nocodes_screen_failed_to_load":
137+
case eventScreenFailedToLoad:
136138
self.screenFailedToLoadEventStreamHandler?.eventSink?(jsonString)
137139

138140
default:

ios/Classes/SwiftQonversionPlugin.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,6 @@ public class SwiftQonversionPlugin: NSObject, FlutterPlugin {
165165
case "showNoCodesScreen":
166166
noCodesPlugin?.showScreen(args, result)
167167
return
168-
169-
case "getAvailableNoCodesEvents":
170-
noCodesPlugin?.getAvailableEvents(result)
171-
return
172168

173169
default:
174170
return result(FlutterMethodNotImplemented)

lib/src/internal/constants.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Constants {
3232
static const kIncludeEmptyContextKey = 'includeEmptyContextKey';
3333
static const kDiscountId = 'discountId';
3434
static const kPromoOffer = 'promoOffer';
35+
static const kConfig = 'config';
3536

3637
// MethodChannel methods names
3738
static const mInitialize = 'initialize';
@@ -68,6 +69,10 @@ class Constants {
6869
static const mDetachUserFromRemoteConfiguration = 'detachUserFromRemoteConfiguration';
6970
static const mCollectAppleSearchAdsAttribution = 'collectAppleSearchAdsAttribution';
7071
static const mPresentCodeRedemptionSheet = 'presentCodeRedemptionSheet';
72+
static const mInitializeNoCodes = 'initializeNoCodes';
73+
static const mSetScreenPresentationConfig = 'setScreenPresentationConfig';
74+
static const mShowNoCodesScreen = 'showNoCodesScreen';
75+
static const mCloseNoCodes = 'closeNoCodes';
7176

7277
// Numeric constants
7378
static const skuDetailsPriceRatio = 1000000;

lib/src/nocodes/nocodes.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,4 @@ abstract class NoCodes {
100100
/// **Platform Support:** iOS and Android. No-op on macOS.
101101
Future<void> close();
102102

103-
/// Get available events
104-
///
105-
/// **Platform Support:** iOS and Android. Returns empty list on macOS.
106-
Future<List<String>> getAvailableEvents();
107103
}

lib/src/nocodes/nocodes_events.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/// Base class for all NoCodes events
1+
/// Base class for all No-Codes events
22
abstract class NoCodesEvent {
33
const NoCodesEvent();
44
}
55

6-
/// Event when NoCodes screen is shown
6+
/// Event when No-Codes screen is shown
77
class NoCodesScreenShownEvent extends NoCodesEvent {
88
final Map<String, dynamic>? payload;
99

lib/src/nocodes/nocodes_internal.dart

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'nocodes_config.dart';
66
import 'nocodes.dart';
77
import 'presentation_config.dart';
88
import 'dart:convert';
9+
import '../internal/constants.dart';
910

1011
class NoCodesInternal implements NoCodes {
1112
final MethodChannel _channel = MethodChannel('qonversion_plugin');
@@ -25,14 +26,13 @@ class NoCodesInternal implements NoCodes {
2526
void _initialize(NoCodesConfig config) {
2627
// NoCodes is not supported on macOS
2728
if (Platform.isMacOS) {
28-
print('NoCodes is not supported on macOS');
2929
return;
3030
}
3131

3232
final args = {
33-
'projectKey': config.projectKey,
33+
Constants.kProjectKey: config.projectKey,
3434
};
35-
_channel.invokeMethod('initializeNoCodes', args);
35+
_channel.invokeMethod(Constants.mInitializeNoCodes, args);
3636
}
3737

3838
@override
@@ -125,44 +125,31 @@ class NoCodesInternal implements NoCodes {
125125
String? contextKey,
126126
}) async {
127127
if (Platform.isMacOS) {
128-
print('NoCodes is not supported on macOS');
129128
return;
130129
}
131130

132131
final args = {
133-
'config': config.toMap(),
134-
if (contextKey != null) 'contextKey': contextKey,
132+
Constants.kConfig: config.toMap(),
133+
if (contextKey != null) Constants.kContextKey: contextKey,
135134
};
136-
await _channel.invokeMethod('setScreenPresentationConfig', args);
135+
await _channel.invokeMethod(Constants.mSetScreenPresentationConfig, args);
137136
}
138137

139138
@override
140139
Future<void> showScreen(String contextKey) async {
141140
if (Platform.isMacOS) {
142-
print('NoCodes is not supported on macOS');
143141
return;
144142
}
145143

146-
await _channel.invokeMethod('showNoCodesScreen', {'contextKey': contextKey});
144+
await _channel.invokeMethod(Constants.mShowNoCodesScreen, {Constants.kContextKey: contextKey});
147145
}
148146

149147
@override
150148
Future<void> close() async {
151149
if (Platform.isMacOS) {
152-
print('NoCodes is not supported on macOS');
153150
return;
154151
}
155152

156-
await _channel.invokeMethod('closeNoCodes');
157-
}
158-
159-
@override
160-
Future<List<String>> getAvailableEvents() async {
161-
if (Platform.isMacOS) {
162-
return [];
163-
}
164-
165-
final result = await _channel.invokeMethod('getAvailableEvents');
166-
return List<String>.from(result ?? []);
153+
await _channel.invokeMethod(Constants.mCloseNoCodes);
167154
}
168155
}

lib/src/nocodes/presentation_config.dart

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
static const kPush = 'Push';
2+
static const kFullScreen = 'FullScreen';
3+
static const kPopover = 'Popover';
4+
static const kAnimated = 'animated';
5+
static const kPresentationStyle = 'presentationStyle';
6+
17
/// Presentation style for NoCodes screens
28
enum NoCodesPresentationStyle {
39
push,
@@ -16,25 +22,25 @@ class NoCodesPresentationConfig {
1622
});
1723

1824
factory NoCodesPresentationConfig.fromMap(Map<String, dynamic> map) {
19-
final presentationStyleString = map['presentationStyle'] as String?;
25+
final presentationStyleString = map[kPresentationStyle] as String?;
2026
NoCodesPresentationStyle presentationStyle;
2127

2228
switch (presentationStyleString) {
23-
case 'Push':
29+
case kPush:
2430
presentationStyle = NoCodesPresentationStyle.push;
2531
break;
26-
case 'FullScreen':
32+
case kFullScreen:
2733
presentationStyle = NoCodesPresentationStyle.fullScreen;
2834
break;
29-
case 'Popover':
35+
case kPopover:
3036
presentationStyle = NoCodesPresentationStyle.popover;
3137
break;
3238
default:
3339
presentationStyle = NoCodesPresentationStyle.fullScreen;
3440
}
3541

3642
return NoCodesPresentationConfig(
37-
animated: map['animated'] as bool? ?? true,
43+
animated: map[kAnimated] as bool? ?? true,
3844
presentationStyle: presentationStyle,
3945
);
4046
}
@@ -43,19 +49,19 @@ class NoCodesPresentationConfig {
4349
String presentationStyleString;
4450
switch (presentationStyle) {
4551
case NoCodesPresentationStyle.push:
46-
presentationStyleString = 'Push';
52+
presentationStyleString = kPush;
4753
break;
4854
case NoCodesPresentationStyle.fullScreen:
49-
presentationStyleString = 'FullScreen';
55+
presentationStyleString = kFullScreen;
5056
break;
5157
case NoCodesPresentationStyle.popover:
52-
presentationStyleString = 'Popover';
58+
presentationStyleString = kPopover;
5359
break;
5460
}
5561

5662
return {
57-
'animated': animated,
58-
'presentationStyle': presentationStyleString,
63+
kAnimated: animated,
64+
kPresentationStyle: presentationStyleString,
5965
};
6066
}
6167

0 commit comments

Comments
 (0)