Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
feat: iOS Universal Links and Android App Links (#229)
Browse files Browse the repository at this point in the history
* API fetches ContentItem from Slug

* Set Up Android and IOS native handling of links

* Wrote the parse

* Wrote index class and client linkparser

* I think I've got the Provider

* Added Provider

* Removed Files

* Added console.logs

* added android logic and got query working

* Updated ios site association

* updated entitlements and such

* Match AppDelegate.m to the React Native Linking documentation

* Changed dan-new link to newspring

* Update packages/newspringchurchapp/src/linking/Provider.js

Co-Authored-By: Michael Neeley <micneeley14@gmail.com>

* Update packages/newspringchurchapp/src/linking/Provider.js

Co-Authored-By: Michael Neeley <micneeley14@gmail.com>

* Update packages/apollos-church-api/src/data/content-items/data-source.js

Co-Authored-By: Michael Neeley <micneeley14@gmail.com>

* Update packages/apollos-church-api/src/data/content-items/data-source.js

Co-Authored-By: Michael Neeley <micneeley14@gmail.com>

* Update packages/apollos-church-api/src/data/content-items/data-source.js

Co-Authored-By: Michael Neeley <micneeley14@gmail.com>

* Update packages/apollos-church-api/src/data/content-items/data-source.js

Co-Authored-By: Michael Neeley <micneeley14@gmail.com>

* Update packages/apollos-church-api/src/data/content-items/data-source.js

Co-Authored-By: Michael Neeley <micneeley14@gmail.com>

* Update packages/apollos-church-api/src/data/content-items/data-source.js

Co-Authored-By: Michael Neeley <micneeley14@gmail.com>

* Update packages/apollos-church-api/src/data/content-items/data-source.js

Co-Authored-By: Michael Neeley <micneeley14@gmail.com>

* Fixed Data Source

* Added tests

* Fixing Tests

* Updated tests

* removed unneccesary function

* Added more tests... they're not working

* Removed Tests womp womp

* Updated from comments

* Made variable singular

* removed line from data-source

* cleaned up code a little
  • Loading branch information
Daniel Edwards authored and redreceipt committed Sep 5, 2019
1 parent 039fe3f commit b9eaa03
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,13 @@ export default class ContentItem extends oldContentItem.dataSource {
});
return features;
}

getBySlug = async (slug) => {
const contentItemSlug = await this.request('ContentChannelItemSlugs')
.filter(`Slug eq '${slug}'`)
.first();
if (!contentItemSlug) throw new Error('Slug does not exist.');

return this.getFromId(`${contentItemSlug.contentChannelItemId}`);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import ApollosConfig from '@apollosproject/config';
const { ROCK_MAPPINGS } = ApollosConfig;

const resolver = {
Query: {
contentItemFromSlug: (root, { slug }, { dataSources }) =>
dataSources.ContentItem.getBySlug(slug),
},
ContentSeriesContentItem: {
theme: (contentItem) => ({
type: () => 'LIGHT',
Expand Down
3 changes: 3 additions & 0 deletions packages/apollos-church-api/src/data/content-items/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ export default gql`
communicator: Person
sermonDate: String
}
extend type Query {
contentItemFromSlug(slug: String!): ContentItem
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,68 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/GOOGLE_MAPS_API_KEY"/>
<activity
android:name=".LaunchActivity"
android:theme="@style/LaunchTheme"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
<intent-filter android:label="filter_react_native">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="peopleapp" android:host="people" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:name=".MainApplication"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustPan"
android:launchMode="singleTask"
/>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/GOOGLE_MAPS_API_KEY" />

<activity
android:name=".LaunchActivity"
android:theme="@style/LaunchTheme"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustPan"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:scheme="newspringchurchapp"
android:host="AppStackNavigator" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:scheme="https"
android:host="AppStackNavigator" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:scheme="https"
android:host="newspring.cc" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.newspringchurchapp;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import org.devio.rn.splashscreen.SplashScreen;
import com.facebook.react.ReactActivity;
Expand All @@ -11,6 +13,10 @@ public class MainActivity extends ReactActivity {
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashScreenTheme);
super.onCreate(savedInstanceState);
// ATTENTION: This was auto-generated to handle app links.
Intent appLinkIntent = getIntent();
String appLinkAction = appLinkIntent.getAction();
Uri appLinkData = appLinkIntent.getData();
}
/**
* Returns the name of the main component registered from JavaScript.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
82A2FF1E6E114D3D962D533D /* libRNPassKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AB4C6D7F52C428FA62777F1 /* libRNPassKit.a */; };
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
834122CBBA8E476A8652994F /* libRNCWebView.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AE039A0F55BB4B989835F759 /* libRNCWebView.a */; };
856D5C6C23172AD80069AAAB /* newspringchurchapp.entitlements in Resources */ = {isa = PBXBuildFile; fileRef = 855CD6D32288B3EA00FB1344 /* newspringchurchapp.entitlements */; };
85FEE849558643629FE5F486 /* Colfax-Black.otf in Resources */ = {isa = PBXBuildFile; fileRef = F910883757A847398A2A8308 /* Colfax-Black.otf */; };
894732A70B4740678E85B593 /* Inter-UI-BoldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 2F5410F239E9477B9C2E86BD /* Inter-UI-BoldItalic.otf */; };
8F4E1AB900E746DB86031C3D /* libRNReanimated.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B83F63C4DE14443BC6C34CF /* libRNReanimated.a */; };
Expand Down Expand Up @@ -546,13 +547,6 @@
remoteGlobalIDString = 134814201AA4EA6300B7C361;
remoteInfo = RNCAsyncStorage;
};
BFE03675230477CC00F44369 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 00F25A7E17B94370985B32E7 /* RNScreens.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = B5C32A4F220C6379000FFB8D;
remoteInfo = "RNScreens-tvOS";
};
BFE7E9D22304794800F89386 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = BFE7E9962304794800F89386 /* RNGestureHandler.xcodeproj */;
Expand Down Expand Up @@ -1070,7 +1064,6 @@
isa = PBXGroup;
children = (
79CEC00F223011FE00D8F685 /* libRNScreens.a */,
BFE03676230477CC00F44369 /* libRNScreens-tvOS.a */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -1366,6 +1359,9 @@
com.apple.Push = {
enabled = 1;
};
com.apple.SafariKeychain = {
enabled = 1;
};
};
};
2D02E47A1E0B4A5D006451C7 = {
Expand Down Expand Up @@ -1981,13 +1977,6 @@
remoteRef = BFE0366A230477CC00F44369 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
BFE03676230477CC00F44369 /* libRNScreens-tvOS.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = "libRNScreens-tvOS.a";
remoteRef = BFE03675230477CC00F44369 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
BFE7E9D32304794800F89386 /* libRNGestureHandler.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
Expand Down Expand Up @@ -2023,6 +2012,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
856D5C6C23172AD80069AAAB /* newspringchurchapp.entitlements in Resources */,
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */,
08CE105F17284254AD54AF84 /* DroidSerif-Bold.ttf in Resources */,
Expand Down
15 changes: 6 additions & 9 deletions packages/newspringchurchapp/ios/newspringchurchapp/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,28 @@

#import "AppDelegate.h"


#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTLinkingManager.h>
#import <React/RCTRootView.h>
#import "RNSplashScreen.h"
#import <React/RCTLinkingManager.h>

@implementation AppDelegate

#import <React/RCTLinkingManager.h>

- (BOOL)application:(UIApplication *)application
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
return [RCTLinkingManager application:application openURL:url options:options];
}

// Only if your app is using [Universal Links](https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html).
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
return [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:newspring.cc</string>
</array>
</dict>
</plist>
21 changes: 12 additions & 9 deletions packages/newspringchurchapp/src/Providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AnalyticsProvider } from '@apollosproject/ui-analytics';

import { MediaPlayerProvider } from '@apollosproject/ui-media-player';
import { NotificationsProvider } from '@apollosproject/ui-notifications';
import ExternalLinkProvider from './linking/Provider';
import { track } from './analytics';

import NavigationService from './NavigationService';
Expand All @@ -23,15 +24,17 @@ const AppProviders = (props) => (
navigateToAuth={() => NavigationService.navigate('Auth')}
closeAuth={() => NavigationService.navigate('Onboarding')}
>
<MediaPlayerProvider>
<AnalyticsProvider trackFunctions={[track]}>
<Providers
themeInput={customTheme}
iconInput={customIcons}
{...props}
/>
</AnalyticsProvider>
</MediaPlayerProvider>
<ExternalLinkProvider navigate={NavigationService.navigate}>
<MediaPlayerProvider>
<AnalyticsProvider trackFunctions={[track]}>
<Providers
themeInput={customTheme}
iconInput={customIcons}
{...props}
/>
</AnalyticsProvider>
</MediaPlayerProvider>
</ExternalLinkProvider>
</AuthProvider>
</NotificationsProvider>
</ClientProvider>
Expand Down
78 changes: 78 additions & 0 deletions packages/newspringchurchapp/src/linking/Provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import URL from 'url';
import querystring from 'querystring';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { Linking } from 'react-native';
import gql from 'graphql-tag';
import { withApollo } from 'react-apollo';

const GET_CONTENT_ITEM_BY_SLUG = gql`
query ContentItemIdFromSlug($slug: String!) {
contentItemFromSlug(slug: $slug) {
id
}
}
`;

class ExternalLinkProvider extends Component {
static propTypes = {
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]).isRequired,
navigate: PropTypes.func.isRequired,
client: PropTypes.shape({
query: PropTypes.func,
addResolvers: PropTypes.func,
readData: PropTypes.func,
onResetStore: PropTypes.func,
}).isRequired,
};

static navigationOptions = {};

componentDidMount() {
console.log('within componentDidMount');
Linking.addEventListener('url', this._handleOpenURL);
Linking.getInitialURL().then((url) => {
if (url) {
this._handleOpenURL({ url });
}
});
}

componentWillUnmount() {
Linking.removeEventListener('url');
}

navigate = (rawUrl) => {
if (!rawUrl) return;
const url = URL.parse(rawUrl);
const route = url.pathname.substring(1);
const args = querystring.parse(url.query);
this.props.navigate(route, args);
};

_handleOpenURL = async (rawUrl) => {
const urlArray = rawUrl.url.split(/[\s/]+/);
const urlSlug = urlArray[urlArray.length - 1];
const {
data: { contentItemFromSlug } = {},
} = await this.props.client.query({
query: GET_CONTENT_ITEM_BY_SLUG,
variables: { slug: urlSlug },
});
if (contentItemFromSlug) {
const newUrl = `newspringchurchapp://AppStackNavigator/ContentSingle?itemId=${
contentItemFromSlug.id
}`;
this.navigate(newUrl);
}
};

render() {
return this.props.children;
}
}

export default withApollo(ExternalLinkProvider);

0 comments on commit b9eaa03

Please sign in to comment.