This repository has been archived by the owner on Jan 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: iOS Universal Links and Android App Links (#229)
* 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
1 parent
039fe3f
commit b9eaa03
Showing
10 changed files
with
185 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |