-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add react native web support #13
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,36 +10,38 @@ export interface EnvironmentInfo { | |
appVersion: string; | ||
appBuildNumber: string; | ||
sdkVersion: string; | ||
osName: string; | ||
osVersion: string; | ||
osName: string | undefined; | ||
osVersion: string | undefined; | ||
} | ||
|
||
export function getEnvironmentInfo(): EnvironmentInfo { | ||
const [osName, osVersion] = getOperatingSystem(); | ||
|
||
const locale = "en-US"; | ||
|
||
return { | ||
const envInfo: EnvironmentInfo = { | ||
appVersion: version.appVersion, | ||
appBuildNumber: version.appBuildNumber, | ||
isDebug: __DEV__, | ||
locale, | ||
osName, | ||
osVersion, | ||
osName: osName, | ||
osVersion: osVersion, | ||
sdkVersion, | ||
}; | ||
} | ||
|
||
function getOperatingSystem(): [string, string] { | ||
switch (Platform.OS) { | ||
case "android": | ||
return ["Android", Platform.constants.Release]; | ||
case "ios": | ||
if (Platform.isPad) { | ||
return ["iPadOS", Platform.Version]; | ||
} | ||
return ["iOS", Platform.Version]; | ||
default: | ||
return ["", ""]; | ||
return envInfo; | ||
|
||
function getOperatingSystem(): [string, string] { | ||
switch (Platform.OS) { | ||
case "android": | ||
return ["Android", Platform.constants.Release]; | ||
case "ios": | ||
if (Platform.isPad) { | ||
return ["iPadOS", Platform.Version]; | ||
} | ||
return ["iOS", Platform.Version]; | ||
default: | ||
return ["", ""]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can add web client here as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I remember correctly I left this empty as the server auto generates the operating system using the User Agent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, wrong place for a comment, I meant just to add another case in switch and return web client information |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
import { NativeModules } from "react-native"; | ||
|
||
const { RNAptabaseModule } = NativeModules; | ||
import { Platform, NativeModules } from "react-native"; | ||
|
||
type VersionObject = { | ||
appVersion: string; | ||
appBuildNumber: string; | ||
}; | ||
|
||
const Version: VersionObject = { | ||
appVersion: RNAptabaseModule?.appVersion?.toString() ?? "", | ||
appBuildNumber: RNAptabaseModule?.appBuildNumber?.toString() ?? "", | ||
}; | ||
let Version: VersionObject; | ||
|
||
if (Platform.OS === "web") { | ||
Version = { | ||
appVersion: "", // can be manually set in AptabaseOptions | ||
appBuildNumber: "" | ||
}; | ||
} else { | ||
const { RNAptabaseModule } = NativeModules; | ||
Version = { | ||
appVersion: RNAptabaseModule?.appVersion?.toString() ?? "", | ||
appBuildNumber: RNAptabaseModule?.appBuildNumber?.toString() ?? "", | ||
}; | ||
} | ||
|
||
export default Version; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we've had trouble in the past with automatically detecting environments
(like in aptabase/aptabase-swift#24 aptabase/aptabase-swift#27 )
I'm a bit reluctant to go this same path.
@Robert27 what are your thoughts and enabling the
WebEventDispatcher
only if a new, explicit option is set inoptions: AptabaseOptions
Would avoid breaking existing usages that simply upgrade, and would enable new integrations to explicitly opt in.