Skip to content

Commit

Permalink
chore: Enable Android/RN/iOS code snippets for feature flags (#19482)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Dec 22, 2023
1 parent 2944c06 commit 915cf58
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion frontend/src/scenes/feature-flags/FeatureFlagCodeOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,16 @@ export const OPTIONS: InstructionOption[] = [

export const LOCAL_EVALUATION_LIBRARIES: string[] = [SDKKey.NODE_JS, SDKKey.PYTHON, SDKKey.RUBY, SDKKey.PHP, SDKKey.GO]

export const PAYLOAD_LIBRARIES: string[] = [SDKKey.JS_WEB, SDKKey.NODE_JS, SDKKey.PYTHON, SDKKey.RUBY, SDKKey.REACT]
export const PAYLOAD_LIBRARIES: string[] = [
SDKKey.JS_WEB,
SDKKey.NODE_JS,
SDKKey.PYTHON,
SDKKey.RUBY,
SDKKey.REACT,
SDKKey.ANDROID,
SDKKey.REACT_NATIVE,
SDKKey.IOS,
]

export const BOOTSTRAPPING_OPTIONS: InstructionOption[] = [
{
Expand Down
33 changes: 30 additions & 3 deletions frontend/src/scenes/feature-flags/FeatureFlagSnippets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,17 @@ if ${conditional}:
)
}

export function AndroidSnippet({ flagKey, multivariant }: FeatureFlagSnippet): JSX.Element {
export function AndroidSnippet({ flagKey, multivariant, payload }: FeatureFlagSnippet): JSX.Element {
const clientSuffix = 'PostHog.'

if (payload) {
return (
<CodeSnippet language={Language.Kotlin} wrap>
{`${clientSuffix}getFeatureFlagPayload("${flagKey}")`}
</CodeSnippet>
)
}

const flagFunction = multivariant ? 'getFeatureFlag' : 'isFeatureEnabled'

const variantSuffix = multivariant ? ` == "example-variant"` : ''
Expand All @@ -327,8 +336,17 @@ export function AndroidSnippet({ flagKey, multivariant }: FeatureFlagSnippet): J
)
}

export function iOSSnippet({ flagKey, multivariant }: FeatureFlagSnippet): JSX.Element {
export function iOSSnippet({ flagKey, multivariant, payload }: FeatureFlagSnippet): JSX.Element {
const clientSuffix = 'posthog.'

if (payload) {
return (
<CodeSnippet language={Language.Swift} wrap>
{`${clientSuffix}getFeatureFlagStringPayload("${flagKey}", defaultValue: "myDefaultValue")`}
</CodeSnippet>
)
}

const flagFunction = multivariant ? 'getFeatureFlag' : 'isFeatureEnabled'

const variantSuffix = multivariant ? ` == 'example-variant'` : ''
Expand All @@ -344,8 +362,17 @@ if (${clientSuffix}${flagFunction}('${flagKey}') ${variantSuffix}) {
)
}

export function ReactNativeSnippet({ flagKey, multivariant }: FeatureFlagSnippet): JSX.Element {
export function ReactNativeSnippet({ flagKey, multivariant, payload }: FeatureFlagSnippet): JSX.Element {
const clientSuffix = 'posthog.'

if (payload) {
return (
<CodeSnippet language={Language.JSX} wrap>
{`${clientSuffix}getFeatureFlagPayload('${flagKey}'`}
</CodeSnippet>
)
}

const flagFunction = multivariant ? 'getFeatureFlag' : 'isFeatureEnabled'

const variantSuffix = multivariant ? ` == 'example-variant'` : ''
Expand Down

0 comments on commit 915cf58

Please sign in to comment.