Skip to content
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

Universal links android #149

Draft
wants to merge 3 commits into
base: markmur/universal-links
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ jobs:

- name: Run Android tests
run: |
echo "STOREFRONT_DOMAIN=\"myshopify.com\"" > sample/.env
yarn module build
yarn sample test:android --no-daemon

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,6 @@ sample/vendor
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Sample app
sample/**/AndroidManifest.xml
18 changes: 18 additions & 0 deletions sample/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,21 @@ apply from: file("../../node_modules/react-native-vector-icons/fonts.gradle")
apply from: file("../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

def properties = loadProperties()
def storefrontDomain = properties.getProperty("STOREFRONT_DOMAIN")

if (!storefrontDomain) {
println("**** Please add a .env file with STOREFRONT_DOMAIN set *****")
}

task generateAndroidManifestFromTemplate {
doLast {
def templateFile = file('src/main/AndroidManifest.template.xml')
def outputFile = file('src/main/AndroidManifest.xml')
def content = templateFile.getText('UTF-8').replace('{{STOREFRONT_DOMAIN}}', "$storefrontDomain")
outputFile.write(content, 'UTF-8')
}
}

preBuild.dependsOn(generateAndroidManifestFromTemplate)
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
android:name=".MainApplication"
Expand All @@ -17,9 +19,21 @@
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">

<!-- This action signifies that the activity is the entry point of the application -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<!-- Configuration for app linking -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<!-- Note: the host here will be replaced on application start -->
<data android:scheme="https" android:host={{STOREFRONT_DOMAIN}} />
</intent-filter>
</activity>
</application>
Expand Down
8 changes: 8 additions & 0 deletions sample/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ buildscript {
}
}

def loadProperties() {
def props = new Properties()
file('../.env').withInputStream {
props.load(it)
}
return props
}

apply plugin: "com.facebook.react.rootproject"
2 changes: 1 addition & 1 deletion sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build:ios": "sh ./scripts/build_ios",
"lint": "yarn typecheck && eslint .",
"ios": "react-native run-ios --simulator 'iPhone 15 Pro'",
"start": "react-native start -- --simulator 'iPhone 15 Pro'",
"start": "react-native start -- --simulator 'iPhone 15 Pro' --reset-cache",
"typecheck": "tsc --noEmit",
"test:ios": "sh ./scripts/test_ios",
"test:android": "sh ./scripts/test_android"
Expand Down
1 change: 0 additions & 1 deletion sample/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ const useInitialURL = (): {url: string | null} => {
};
};

// This code is meant as example only.
class StorefrontURL {
readonly url: string;

Expand Down
Loading