Skip to content

Commit

Permalink
v1.13.0 (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
SwiftyAlex authored Nov 1, 2022
1 parent c90c23f commit 96c1cb4
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 16 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,5 @@ dependencies {
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.appcompat:appcompat:1.3.1"
implementation "com.unflow:unflow-ui:1.12.1"
implementation "com.unflow:unflow-ui:1.13.0"
}
20 changes: 20 additions & 0 deletions android/src/main/java/com/unflow/reactnative/UnflowModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.unflow.androidsdk.UnflowSdk
import com.unflow.androidsdk.ui.theme.Fonts
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.collectLatest
import java.util.*

class UnflowModule(
private val reactContext: ReactApplicationContext,
Expand Down Expand Up @@ -86,6 +87,25 @@ class UnflowModule(
UnflowSdk.client().openScreen(screenId = screenId.toLong())
}

@ReactMethod
fun setLocale(locale: String, language: String) {
val localeObject = Locale.getAvailableLocales().firstOrNull { it.toString() == locale }
val languageObject = Locale.getAvailableLocales().firstOrNull { it.language == language }

if(localeObject == null) {
Log.e("UNFLOW", "Unable to set locale as ${locale}")
}
if (languageObject == null) {
Log.e("UNFLOW", "Unable to set language as ${language}")
}

localeObject?.let { locale ->
languageObject?.let { languageLocale ->
UnflowSdk.client().setUserLocale(locale = locale, language = languageLocale)
}
}
}

@ReactMethod
fun trackEvent(eventName: String, metadata: ReadableMap) {
val mappedMetadata = metadata.toHashMap() as? Map<String, Any?>
Expand Down
10 changes: 5 additions & 5 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,10 @@ PODS:
- React-RCTImage
- RNSVG (12.3.0):
- React-Core
- Unflow (1.12.1)
- unflow-react-native (1.12.2):
- Unflow (1.13.0-swift-5.6)
- unflow-react-native (1.13.0):
- React-Core
- Unflow (= 1.12.1)
- Unflow (= 1.13.0-swift-5.6)
- Yoga (1.14.0)
- YogaKit (1.18.1):
- Yoga (~> 1.14)
Expand Down Expand Up @@ -562,8 +562,8 @@ SPEC CHECKSUMS:
RNGestureHandler: 6e757e487a4834e7280e98e9bac66d2d9c575e9c
RNScreens: 40a2cb40a02a609938137a1e0acfbf8fc9eebf19
RNSVG: 302bfc9905bd8122f08966dc2ce2d07b7b52b9f8
Unflow: 6cdf0cea5e2ff605321d73b663b7e5ddce8aa19e
unflow-react-native: 3f2ce08848258c1c258835e698f95172ef9be252
Unflow: 085a89a706e4ea0b484388f87ae3af43f19ff91a
unflow-react-native: 2a0f3c13439aac92c011357af0cf1dac7be85949
Yoga: 5cbf25add73edb290e1067017690f7ebf56c5468
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

Expand Down
31 changes: 24 additions & 7 deletions ios/Unflow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,18 @@ class Unflow: NSObject {
@objc(setAttributes:)
func setAttributes(attributes: NSDictionary) -> Void {
if #available(iOS 13.0, *) {
guard let mappedAttribtues = attributes as? [String: String] else {
return
}
Task {
await MainActor.run(body: {
UnflowSDK.client.setAttributes(attributes: mappedAttribtues)
})
do {
// Simply checks for valid JSON

_ = try EventMetadata(from: attributes)
let bridgedAttributes = UnflowMetadataBridge.convert(metadata: attributes)
Task {
await MainActor.run(body: {
UnflowSDK.client.setAttributes(attributes: bridgedAttributes)
})
}
} catch {
print("Unflow: Unable to set attributes")
}
}
}
Expand Down Expand Up @@ -154,6 +159,18 @@ class Unflow: NSObject {
} catch {}
}
}

@objc(setLocale:withLanguage:)
func setLocale(locale: String, language: String) {
if #available(iOS 13, *) {
guard Locale.availableIdentifiers.contains(locale) else {
print("Unflow: Locale '\(locale)' not valid")
return
}
let locale = Locale.init(identifier: locale)
UnflowSDK.client.setUserLocale(locale: locale, language: language)
}
}

@objc(trackEvent:withMetadata:)
func trackEvent(eventName: String, metadata: NSDictionary) -> Void {
Expand Down
1 change: 1 addition & 0 deletions ios/UnflowBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ @interface RCT_EXTERN_MODULE(Unflow, NSObject)
RCT_EXTERN_METHOD(addListener:(NSString *)eventName)
RCT_EXTERN_METHOD(removeListeners:(NSInteger)count)
RCT_EXTERN_METHOD(setPushToken:(NSString *)token)
RCT_EXTERN_METHOD(setLocale:(NSString *)locale withLanguage:(NSString*)language)
@end
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unflow-react-native",
"version": "1.12.2",
"version": "1.13.0",
"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.",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
1 change: 1 addition & 0 deletions src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export type UnflowType = {
openScreen(screenId: number): null;
trackEvent(eventName: string, metadata: Metadata): null;
setPushToken(token: string): null;
setLocale(locale: string, language: string): null;
deregisterToken(): null;
addAnalyticsListener: (
callback: (event: UnflowEvent) => void
Expand Down
4 changes: 2 additions & 2 deletions unflow-react-native.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Pod::Spec.new do |s|
s.source_files = "ios/**/*.{h,m,mm,swift}"

s.dependency "React-Core"
s.dependency "Unflow", "1.12.1"
end
s.dependency "Unflow", "1.13.0-swift-5.6"
end

0 comments on commit 96c1cb4

Please sign in to comment.