Skip to content

Commit

Permalink
Merge pull request #1307 from appwrite/feat-react-native-platform
Browse files Browse the repository at this point in the history
feat: react native platform
  • Loading branch information
TorstenDittmann authored Aug 23, 2024
2 parents b1ddd05 + 7aaf29f commit edf5392
Show file tree
Hide file tree
Showing 9 changed files with 520 additions and 310 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"e2e:ui": "playwright test tests/e2e --ui"
},
"dependencies": {
"@appwrite.io/console": "npm:[email protected]",
"@appwrite.io/console": "1.0.0",
"@appwrite.io/pink": "0.25.0",
"@appwrite.io/pink-icons": "0.25.0",
"@popperjs/core": "^2.11.8",
Expand Down
522 changes: 270 additions & 252 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
title: 'Android',
icon: 'color/android',
platform: Platform.Android
},
{
title: 'React Native',
icon: 'color/react',
platform: Platform.ReactNative
}
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import CreateApple from './createApple.svelte';
import CreateFlutter from './createFlutter.svelte';
import CreateWeb from './createWeb.svelte';
import CreateReactNative from './createReactNative.svelte';
import { versions } from './wizard/store';
export enum Platform {
Web,
Flutter,
Android,
Apple
Apple,
ReactNative
}
export async function addPlatform(type: Platform) {
Expand All @@ -24,7 +26,8 @@
[Platform.Web]: CreateWeb,
[Platform.Flutter]: CreateFlutter,
[Platform.Android]: CreateAndroid,
[Platform.Apple]: CreateApple
[Platform.Apple]: CreateApple,
[Platform.ReactNative]: CreateReactNative
};
</script>

Expand Down Expand Up @@ -52,7 +55,9 @@
'flutter-macos' = 'macOS',
'flutter-windows' = 'Windows',
'flutter-web' = 'Web',
'web' = 'Web'
'web' = 'Web',
'react-native-android' = 'Android',
'react-native-ios' = 'iOS'
}
let showDropdown = false;
let showDropdownEmpty = false;
Expand All @@ -61,6 +66,8 @@
const getPlatformInfo = (platform: string) => {
if (platform.includes('flutter')) {
return 'color/flutter';
} else if (platform.includes('react-native')) {
return 'color/react';
} else if (platform.includes('apple')) {
return 'color/apple';
} else if (platform.includes('android')) {
Expand Down Expand Up @@ -89,6 +96,8 @@
<DropListItem on:click={() => addPlatform(Platform.Flutter)}>Flutter app</DropListItem>
<DropListItem on:click={() => addPlatform(Platform.Android)}>Android app</DropListItem>
<DropListItem on:click={() => addPlatform(Platform.Apple)}>Apple app</DropListItem>
<DropListItem on:click={() => addPlatform(Platform.ReactNative)}
>React Native app</DropListItem>
</svelte:fragment>
</DropList>
</ContainerHeader>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<script lang="ts">
import { Wizard } from '$lib/layout';
import { invalidate } from '$app/navigation';
import { wizard } from '$lib/stores/wizard';
import { createPlatform } from './wizard/store';
import type { WizardStepsType } from '$lib/layout/wizard.svelte';
import Step1 from './wizard/react-native/step1.svelte';
import Step2 from './wizard/react-native/step2.svelte';
import Step3 from './wizard/react-native/step3.svelte';
import Step4 from './wizard/step4.svelte';
import { Dependencies } from '$lib/constants';
async function onFinish() {
await Promise.all([invalidate(Dependencies.PROJECT), invalidate(Dependencies.PLATFORMS)]);
createPlatform.reset();
wizard.hide();
}
const stepsComponents: WizardStepsType = new Map();
stepsComponents.set(1, {
label: 'Settings',
component: Step1
});
stepsComponents.set(2, {
label: 'Install',
component: Step2,
optional: true
});
stepsComponents.set(3, {
label: 'Import',
component: Step3,
optional: true
});
stepsComponents.set(4, {
label: 'Build',
component: Step4,
optional: true
});
</script>

<Wizard
title="Add a React Native platform"
steps={stepsComponents}
on:finish={onFinish}
on:exit={onFinish}
finalAction="Go to dashboard" />
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
const projectId = $page.params.project;
const suggestions = ['*.vercel.app', '*.netlify.app', '*.gitpod.io'];
const placeholder: Record<
PlatformType,
{
name: string;
hostname: string;
tooltip: string;
}
const placeholder: Partial<
Record<
PlatformType,
{
name: string;
hostname: string;
tooltip: string;
}
>
> = {
[PlatformType.Flutterandroid]: {
name: 'My Android App',
Expand Down Expand Up @@ -69,60 +71,16 @@
name: 'My Windows App',
hostname: 'appname',
tooltip: 'Your application name'
},
// The following are not used, but added to avoid TS errors
[PlatformType.Web]: {
name: '',
hostname: '',
tooltip: ''
},
[PlatformType.Appleios]: {
name: '',
hostname: '',
tooltip: ''
},
[PlatformType.Applemacos]: {
name: '',
hostname: '',
tooltip: ''
},
[PlatformType.Applewatchos]: {
name: '',
hostname: '',
tooltip: ''
},
[PlatformType.Appletvos]: {
name: '',
hostname: '',
tooltip: ''
},
[PlatformType.Android]: {
name: '',
hostname: '',
tooltip: ''
},
[PlatformType.Unity]: {
name: '',
hostname: '',
tooltip: ''
}
};
const hostname: Record<PlatformType, string> = {
const hostname: Partial<Record<PlatformType, string>> = {
[PlatformType.Flutterandroid]: 'Package Name',
[PlatformType.Flutterios]: 'Bundle ID',
[PlatformType.Flutterlinux]: 'Package Name',
[PlatformType.Fluttermacos]: 'Bundle ID',
[PlatformType.Flutterweb]: 'Hostname',
[PlatformType.Flutterwindows]: 'Package Name',
// The following are not used, but added to avoid TS errors
[PlatformType.Web]: '',
[PlatformType.Appleios]: '',
[PlatformType.Applemacos]: '',
[PlatformType.Applewatchos]: '',
[PlatformType.Appletvos]: '',
[PlatformType.Android]: '',
[PlatformType.Unity]: ''
[PlatformType.Flutterwindows]: 'Package Name'
};
async function beforeSubmit() {
Expand All @@ -148,7 +106,7 @@
}
$: registee = {
[PlatformType.Flutterandroid]: 'package name',
[PlatformType.Flutterandroid]: 'Package name',
[PlatformType.Flutterios]: 'Bundle ID',
[PlatformType.Flutterlinux]: 'Package name',
[PlatformType.Fluttermacos]: 'Bundle ID',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<script lang="ts">
import { page } from '$app/stores';
import { Pill } from '$lib/elements';
import { FormList, InputText } from '$lib/elements/forms';
import { WizardStep } from '$lib/layout';
import { sdk } from '$lib/stores/sdk';
import { createPlatform } from '../store';
import { Submit, trackEvent } from '$lib/actions/analytics';
import { PlatformType } from '@appwrite.io/console';
import { isValueOfStringEnum } from '$lib/helpers/types';
let platform: PlatformType = isValueOfStringEnum(PlatformType, $createPlatform.type)
? $createPlatform.type
: PlatformType.Reactnativeandroid;
const projectId = $page.params.project;
const placeholder: Partial<
Record<
PlatformType,
{
name: string;
hostname: string;
tooltip: string;
}
>
> = {
[PlatformType.Reactnativeandroid]: {
name: 'My Android App',
hostname: 'com.company.appname',
tooltip:
'Your package name is generally the applicationId in your app-level build.gradle file.'
},
[PlatformType.Reactnativeios]: {
name: 'My iOS App',
hostname: 'com.company.appname',
tooltip:
"You can find your Bundle Identifier in the General tab for your app's primary target in Xcode."
}
};
const hostname: Partial<Record<PlatformType, string>> = {
[PlatformType.Reactnativeandroid]: 'Package Name',
[PlatformType.Reactnativeios]: 'Bundle ID'
};
async function beforeSubmit() {
if ($createPlatform.$id) {
await sdk.forConsole.projects.deletePlatform(projectId, $createPlatform.$id);
}
const response = await sdk.forConsole.projects.createPlatform(
projectId,
platform,
$createPlatform.name,
$createPlatform.key
);
trackEvent(Submit.PlatformCreate, {
type: platform
});
$createPlatform.$id = response.$id;
$createPlatform.type = platform;
}
$: registee = {
[PlatformType.Reactnativeandroid]: 'Package name',
[PlatformType.Reactnativeios]: 'Bundle ID'
}[platform];
</script>

<WizardStep {beforeSubmit}>
<svelte:fragment slot="title">{registee} registration</svelte:fragment>
<svelte:fragment slot="subtitle">
<div class="u-flex u-gap-16 u-margin-block-start-8 u-flex-wrap">
<Pill
button
on:click={() => (platform = PlatformType.Reactnativeandroid)}
selected={platform === PlatformType.Reactnativeandroid}>
Android
</Pill>
<Pill
button
on:click={() => (platform = PlatformType.Reactnativeios)}
selected={platform === PlatformType.Reactnativeios}>
iOS
</Pill>
</div>
</svelte:fragment>

<FormList isCommonSection>
<InputText
id="name"
label="Name"
placeholder={placeholder[platform].name}
required
bind:value={$createPlatform.name} />
<InputText
id="key"
label={hostname[platform]}
placeholder={placeholder[platform].hostname}
tooltip={placeholder[platform].tooltip}
required
bind:value={$createPlatform.key} />
</FormList>
</WizardStep>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script lang="ts">
import { Code } from '$lib/components';
import { WizardStep } from '$lib/layout';
const example = `npx expo install react-native-appwrite react-native-url-polyfill`;
</script>

<WizardStep>
<svelte:fragment slot="title">Install</svelte:fragment>

<p>Install the Appwrite SDK for React Native and required dependencies.</p>
<Code label="Bash" language="sh" code={example} withCopy />
</WizardStep>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<script lang="ts">
import { Alert, Code } from '$lib/components';
import { WizardStep } from '$lib/layout';
import { isSelfHosted } from '$lib/system';
import { sdk } from '$lib/stores/sdk';
import { createPlatform } from '../store';
import Id from '$lib/components/id.svelte';
const { endpoint, project } = sdk.forProject.client.config;
const code = `import { Client, Account, ID } from 'react-native-appwrite';
const client = new Client();
const client
.setEndpoint('${endpoint}')
.setProject('${project}')
.setPlatform('${$createPlatform.key}');`;
let showAlert = true;
</script>

<WizardStep>
<svelte:fragment slot="title">Initialize</svelte:fragment>

<h2 class="heading-level-7">Initialize your SDK</h2>
<p data-private>
Initialize your SDK by pointing the client to your Appwrite project using your <Id
value={project}>Project ID</Id>
</p>
<div class="u-margin-block-start-16">
<Code
label="React Native"
labelIcon="code"
language="js"
{code}
withCopy
withLineNumbers
noMargin />
</div>
<p class="common-section">
Before sending any API calls to your new Appwrite project, make sure your device or emulator
has network access to your Appwrite project's hostname or IP address.
</p>
{#if showAlert && isSelfHosted}
<div class="common-section">
<Alert type="info" on:dismiss={() => (showAlert = false)}>
<svelte:fragment slot="title">For self-hosted solutions</svelte:fragment>
When connecting to a locally hosted Appwrite project from an emulator or a mobile device,
you should use the private IP of the device running your Appwrite project as the hostname
of the endpoint instead of localhost. You can also use a service like ngrok to proxy
the Appwrite server.
</Alert>
</div>
{/if}
</WizardStep>

0 comments on commit edf5392

Please sign in to comment.