Skip to content

Commit 413d45b

Browse files
authored
v1.15.0
1 parent 91eeca0 commit 413d45b

13 files changed

+119
-13
lines changed

android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,5 @@ dependencies {
123123
implementation "com.facebook.react:react-native:+"
124124
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
125125
implementation "androidx.appcompat:appcompat:1.3.1"
126-
implementation "com.unflow:unflow-ui:1.14.2"
126+
implementation "com.unflow:unflow-ui:1.15.0"
127127
}

android/src/main/java/com/unflow/reactnative/UnflowModule.kt

+25
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ class UnflowModule(
121121
UnflowSdk.client().deregisterPushToken()
122122
}
123123

124+
@ReactMethod
125+
fun clearUserSession() {
126+
scope.launch {
127+
UnflowSdk.client().clearUserSession()
128+
}
129+
}
130+
124131
@ReactMethod
125132
@Suppress("UNUSED_PARAMETER")
126133
fun addListener(eventName: String) {}
@@ -227,6 +234,24 @@ private class UnflowAnalyticsListener(
227234
emitEvent(event)
228235
}
229236

237+
override fun onAttributesUpdate(attributes: Map<String, Any?>) {
238+
val attributesMap = WritableNativeMap()
239+
attributes.forEach {
240+
when(it.value) {
241+
is Long -> { attributesMap.putDouble(it.key, ((it.value as? Long) ?: 0).toDouble()) }
242+
is Int -> { attributesMap.putInt(it.key, ((it.value as? Int) ?: 0)) }
243+
is String -> { attributesMap.putString(it.key, (it.value as? String)) }
244+
is Boolean -> { attributesMap.putBoolean(it.key, (it.value as? Boolean) ?: false) }
245+
null -> { attributesMap.putNull(it.key) }
246+
is List<*> -> { attributesMap.putArray(it.key, makeNativeArray(it.value)) }
247+
}
248+
}
249+
250+
reactContext
251+
.getJSModule(RCTDeviceEventEmitter::class.java)
252+
.emit("AttributesUpdated", attributesMap)
253+
}
254+
230255
@ReactMethod
231256
fun emitEvent(event: UnflowEvent) {
232257
val eventMap = WritableNativeMap()

example/ios/Podfile.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,10 @@ PODS:
352352
- React-RCTImage
353353
- RNSVG (12.3.0):
354354
- React-Core
355-
- Unflow (1.14.2-swift-5.6)
356-
- unflow-react-native (1.14.2):
355+
- Unflow (1.15.0-swift-5.6)
356+
- unflow-react-native (1.15.0):
357357
- React-Core
358-
- Unflow (= 1.14.2-swift-5.6)
358+
- Unflow (= 1.15.0-swift-5.6)
359359
- Yoga (1.14.0)
360360
- YogaKit (1.18.1):
361361
- Yoga (~> 1.14)
@@ -562,8 +562,8 @@ SPEC CHECKSUMS:
562562
RNGestureHandler: 6e757e487a4834e7280e98e9bac66d2d9c575e9c
563563
RNScreens: 40a2cb40a02a609938137a1e0acfbf8fc9eebf19
564564
RNSVG: 302bfc9905bd8122f08966dc2ce2d07b7b52b9f8
565-
Unflow: a1eaec5ac335b44863694ded2a708e951b611f00
566-
unflow-react-native: c8d67fa5edf936489063f5f16000876b91efcba1
565+
Unflow: cfb8a107a7df1b24ad26a87d84361322388037fb
566+
unflow-react-native: 679d2ec0f8a1bf65db8d62f428fd53a20c4d4b06
567567
Yoga: 5cbf25add73edb290e1067017690f7ebf56c5468
568568
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
569569

example/src/App.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,21 @@ export default function App() {
2929
console.log(event);
3030
};
3131

32+
const unflowAttributesListener = (attributes) => {
33+
console.log(attributes);
34+
};
35+
3236
useEffect(() => {
33-
let subscription = Unflow.addAnalyticsListener(unflowAnalyticsListener);
34-
return () => Unflow.removeAnalyticsListener(subscription);
37+
let analyticsSubscription = Unflow.addAnalyticsListener(
38+
unflowAnalyticsListener
39+
);
40+
let attributesSubscription = Unflow.addAttributesListener(
41+
unflowAttributesListener
42+
);
43+
return () => {
44+
Unflow.removeAnalyticsListener(analyticsSubscription);
45+
Unflow.removeAttributesListener(attributesSubscription);
46+
};
3547
}, []);
3648

3749
return (

example/src/DetailsScreen.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
UnflowMark,
2121
} from './icons';
2222
import Section from './Section';
23+
import Unflow from 'unflow-react-native';
2324

2425
const LINKS_DATA = [
2526
{
@@ -77,7 +78,9 @@ export default function SettingsScreen() {
7778
let clearStorage = async () => {
7879
await storeData({ screens: [], events: [] });
7980
};
80-
81+
let resetSession = () => {
82+
Unflow.clearUserSession();
83+
};
8184
return (
8285
<View style={styles.container}>
8386
<Section title="Useful links">
@@ -98,6 +101,9 @@ export default function SettingsScreen() {
98101
/>
99102
</View>
100103
</Section>
104+
<TouchableOpacity style={styles.destructiveButton} onPress={resetSession}>
105+
<Text style={styles.destructiveButtonText}>Reset User Session</Text>
106+
</TouchableOpacity>
101107
<TouchableOpacity style={styles.destructiveButton} onPress={clearStorage}>
102108
<Text style={styles.destructiveButtonText}>Clear Cache</Text>
103109
</TouchableOpacity>
@@ -145,6 +151,7 @@ const styles = StyleSheet.create({
145151
backgroundColor: '#FACDCD',
146152
marginHorizontal: 16,
147153
paddingVertical: 12,
154+
marginBottom: 12,
148155
borderRadius: 32,
149156
alignItems: 'center',
150157
},

ios/Unflow.swift

+24
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ class UnflowAnalyticsListener: UnflowUI.AnalyticsListener {
2121
}
2222
}
2323
}
24+
25+
func onAttributesUpdate(attributes: [String: UnflowUI.UnflowAnalyticsValue]) {
26+
if #available(iOS 13, *) {
27+
Task {
28+
await MainActor.run(body: {
29+
EventEmitter.sharedInstance.dispatch(
30+
name: EventName.attributesUpdated.key,
31+
body: attributes
32+
)
33+
})
34+
}
35+
}
36+
}
2437
}
2538

2639

@@ -197,6 +210,17 @@ class Unflow: NSObject {
197210
}
198211
}
199212

213+
@objc(clearUserSession)
214+
func clearUserSession() -> Void {
215+
if #available(iOS 13.0, *) {
216+
Task {
217+
await MainActor.run(body: {
218+
UnflowSDK.client.clearUserSession()
219+
})
220+
}
221+
}
222+
}
223+
200224
@objc(openers:)
201225
func openers(spaceKey: String) -> Void {
202226
if #available(iOS 13.0, *) {

ios/UnflowBridge.m

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ @interface RCT_EXTERN_MODULE(Unflow, NSObject)
1212
RCT_EXTERN_METHOD(openScreen:(double *)screenId)
1313
RCT_EXTERN_METHOD(trackEvent:(NSString *)eventName withMetadata:(NSDictionary *)metadata)
1414
RCT_EXTERN_METHOD(deregisterToken)
15+
RCT_EXTERN_METHOD(clearUserSession)
1516
RCT_EXTERN_METHOD(openers:(NSString *)spaceKey)
1617
RCT_EXTERN_METHOD(spaces)
1718
RCT_EXTERN_METHOD(addListener:(NSString *)eventName)

ios/UnflowEventEmitter.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class UnflowEventEmitter: RCTEventEmitter {
3434
}
3535

3636
@objc enum EventName: Int, CaseIterable {
37-
case openersChanged, spacesChanged, eventReceived
37+
case openersChanged, spacesChanged, eventReceived, attributesUpdated
3838

3939
var key: String {
4040
switch self {
@@ -44,6 +44,8 @@ class UnflowEventEmitter: RCTEventEmitter {
4444
return "SpacesChanged"
4545
case .eventReceived:
4646
return "EventReceived"
47+
case .attributesUpdated:
48+
return "AttributesUpdated"
4749
}
4850
}
4951
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "unflow-react-native",
3-
"version": "1.14.2",
3+
"version": "1.15.0",
44
"description": "Tired of building the same simple screens over and over again? Empower your product team to create and ship content using the Unflow mobile SDK.",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

src/attributes-listener.tsx

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { EmitterSubscription } from 'react-native';
2+
import { EventEmitter } from './native-emitter';
3+
import type { Metadata } from './types';
4+
5+
export function addAttributesListener(
6+
callback: (attributes: Metadata) => void
7+
): EmitterSubscription | undefined {
8+
let subscription: EmitterSubscription | undefined;
9+
if (EventEmitter) {
10+
subscription = EventEmitter.addListener('AttributesUpdated', callback);
11+
}
12+
return subscription;
13+
}
14+
15+
export function removeAttributesListener(
16+
subscription: EmitterSubscription
17+
): void {
18+
if (subscription) subscription.remove();
19+
}

src/index.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import {
33
addAnalyticsListener,
44
removeAnalyticsListener,
55
} from './analytics-listener';
6+
import {
7+
addAttributesListener,
8+
removeAttributesListener,
9+
} from './attributes-listener';
610
import OpenerView, { useSpace } from './opener-view';
711
import SpacesView, { useSpaces } from './spaces-view';
812
import type { UnflowType } from './types';
@@ -59,6 +63,10 @@ function setPushToken(value: string) {
5963
Unflow.setUserId(value);
6064
}
6165

66+
function clearUserSession() {
67+
Unflow.clearUserSession();
68+
}
69+
6270
export default {
6371
...Unflow,
6472
initialize,
@@ -67,6 +75,9 @@ export default {
6775
trackEvent,
6876
openScreen,
6977
setPushToken,
78+
clearUserSession,
7079
addAnalyticsListener: addAnalyticsListener,
7180
removeAnalyticsListener: removeAnalyticsListener,
81+
addAttributesListener: addAttributesListener,
82+
removeAttributesListener: removeAttributesListener,
7283
} as UnflowType;

src/types.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ type MetadataAttributeValue =
109109
| AttributeValue[]
110110
| AttributeObject[];
111111

112-
type Metadata = {
112+
export type Metadata = {
113113
[key: string]: MetadataAttributeValue;
114114
};
115115

@@ -143,4 +143,9 @@ export type UnflowType = {
143143
callback: (event: UnflowEvent) => void
144144
) => EmitterSubscription;
145145
removeAnalyticsListener: (subscription: EmitterSubscription) => void;
146+
addAttributesListener: (
147+
callback: (attributes: Metadata) => void
148+
) => EmitterSubscription;
149+
removeAttributesListener: (subscription: EmitterSubscription) => void;
150+
clearUserSession(): null;
146151
};

unflow-react-native.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ Pod::Spec.new do |s|
1616
s.source_files = "ios/**/*.{h,m,mm,swift}"
1717

1818
s.dependency "React-Core"
19-
s.dependency "Unflow", "1.14.2-swift-5.6"
19+
s.dependency "Unflow", "1.15.0-swift-5.6"
2020
end

0 commit comments

Comments
 (0)