-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module): Initial Launch of react-native-cookies
BREAKING CHANGE: Temporary breaking change to trigger semantic major version bump.
- Loading branch information
Showing
23 changed files
with
6,809 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,47 @@ | ||
version: 2 | ||
jobs: | ||
build: | ||
docker: | ||
- image: debian:stretch | ||
version: 2.1 | ||
orbs: | ||
rn: react-native-community/react-native@1.3.0 | ||
|
||
jobs: | ||
checkout_code: | ||
executor: rn/linux_js | ||
steps: | ||
- checkout | ||
- persist_to_workspace: | ||
root: . | ||
paths: . | ||
|
||
analyse_js: | ||
executor: rn/linux_js | ||
steps: | ||
- attach_workspace: | ||
at: . | ||
- rn/yarn_install | ||
- run: | ||
name: Greeting | ||
command: echo Hello, world. | ||
name: Run ESLint | ||
command: yarn lint | ||
|
||
release: | ||
executor: rn/linux_js | ||
steps: | ||
- attach_workspace: | ||
at: . | ||
- rn/yarn_install | ||
- run: | ||
name: Print the Current Time | ||
command: date | ||
name: Publish to NPM | ||
command: yarn semantic-release || true | ||
|
||
workflows: | ||
ci: | ||
jobs: | ||
- checkout_code | ||
- analyse_js: | ||
requires: | ||
- checkout_code | ||
- release: | ||
requires: | ||
- analyse_js | ||
filters: | ||
branches: | ||
only: master | ||
|
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,3 @@ | ||
{ | ||
"extends": "@react-native-community" | ||
} |
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 @@ | ||
*.pbxproj -text |
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,48 @@ | ||
# OSX | ||
# | ||
.DS_Store | ||
|
||
# node.js | ||
# | ||
node_modules/ | ||
npm-debug.log | ||
yarn-error.log | ||
|
||
# Xcode | ||
# | ||
build/ | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata | ||
*.xccheckout | ||
*.moved-aside | ||
DerivedData | ||
*.hmap | ||
*.ipa | ||
*.xcuserstate | ||
project.xcworkspace | ||
|
||
# Android/IntelliJ | ||
# | ||
build/ | ||
.idea | ||
.gradle | ||
local.properties | ||
*.iml | ||
.classpath | ||
.project | ||
.settings | ||
|
||
# BUCK | ||
buck-out/ | ||
\.buckd/ | ||
*.keystore | ||
|
||
# VS Code | ||
.vscode |
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,4 @@ | ||
.eslintrc | ||
.prettierrc | ||
.releaserc | ||
.circleci/* |
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,5 @@ | ||
{ | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
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,15 @@ | ||
{ | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator", | ||
"@semantic-release/npm", | ||
"@semantic-release/github", | ||
[ | ||
"@semantic-release/git", | ||
{ | ||
"assets": "package.json", | ||
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" | ||
} | ||
] | ||
] | ||
} |
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 |
---|---|---|
@@ -1,2 +1,196 @@ | ||
# @react-native-community/react-native-cookies | ||
# React Native Cookies - A Cookie Manager for React Native | ||
Cookie Manager for React Native | ||
|
||
## Maintainers | ||
- [Jason Safaiyeh](https://github.com/safaiyeh) ([Twitter @safaiyeh](https://twitter.com/safaiyeh)) from [Sumo Logic](https://www.sumologic.com) | ||
|
||
## Platforms Supported | ||
- [x] iOS | ||
- [x] Android | ||
|
||
Currently lacking support for Windows, Web, and Expo. Support for these platforms will created when there is a need for them. Starts with a posted issue. | ||
|
||
## Installation | ||
|
||
``` | ||
yarn add @react-native-community/react-native-cookies | ||
``` | ||
|
||
|
||
## Setup (React Native < 0.60.0) | ||
|
||
### Automatic (recommended) | ||
|
||
``` | ||
react-native link @react-native-community/react-native-cookies | ||
``` | ||
|
||
### Manual | ||
|
||
If automatic linking does not work, you can manually link this library by following the instructions below: | ||
|
||
#### iOS | ||
|
||
1. Open your project in Xcode, right click on `Libraries` and click `Add | ||
Files to "Your Project Name"` Look under `node_modules/@react-native-community/react-native-cookies/ios` and add `RNCookieManagerIOS.xcodeproj`. | ||
2. Add `libRNCookieManagerIOS.a` to `Build Phases -> Link Binary With Libraries. | ||
3. Clean and rebuild your project | ||
|
||
#### Android | ||
|
||
Run `react-native link` to link the react-native-cookies library. | ||
|
||
Or if you have trouble, make the following additions to the given files manually: | ||
|
||
**android/settings.gradle** | ||
|
||
```gradle | ||
include ':@react-native-community_react-native-cookies' | ||
project(':@react-native-community_react-native-cookies').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/react-native-cookies/android') | ||
``` | ||
|
||
**android/app/build.gradle** | ||
|
||
```gradle | ||
dependencies { | ||
... | ||
implementation project(':@react-native-community_react-native-cookies') | ||
} | ||
``` | ||
|
||
**MainApplication.java** | ||
|
||
On top, where imports are: | ||
|
||
```java | ||
import com.reactnativecommunity.cookies.CookieManagerPackage; | ||
``` | ||
|
||
Add the `CookieManagerPackage` class to your list of exported packages. | ||
|
||
```java | ||
@Override | ||
protected List<ReactPackage> getPackages() { | ||
return Arrays.asList( | ||
new MainReactPackage(), | ||
new CookieManagerPackage() | ||
); | ||
} | ||
``` | ||
|
||
|
||
|
||
## Usage | ||
|
||
```javascript | ||
import CookieManager from 'react-native-cookie-store'; | ||
|
||
// set a cookie (IOS ONLY) | ||
CookieManager.set({ | ||
name: 'myCookie', | ||
value: 'myValue', | ||
domain: 'some domain', | ||
origin: 'some origin', | ||
path: '/', | ||
version: '1', | ||
expiration: '2015-05-30T12:30:00.00-05:00' | ||
}).then((res) => { | ||
console.log('CookieManager.set =>', res); | ||
}); | ||
|
||
// Set cookies from a response header | ||
// This allows you to put the full string provided by a server's Set-Cookie | ||
// response header directly into the cookie store. | ||
CookieManager.setFromResponse( | ||
'http://example.com', | ||
'user_session=abcdefg; path=/; expires=Thu, 1 Jan 2030 00:00:00 -0000; secure; HttpOnly') | ||
.then((res) => { | ||
// `res` will be true or false depending on success. | ||
console.log('CookieManager.setFromResponse =>', res); | ||
}); | ||
|
||
// Get cookies as a request header string | ||
CookieManager.get('http://example.com') | ||
.then((res) => { | ||
console.log('CookieManager.get =>', res); // => 'user_session=abcdefg; path=/;' | ||
}); | ||
|
||
// list cookies (IOS ONLY) | ||
// useWebKit: boolean | ||
CookieManager.getAll(useWebKit) | ||
.then((res) => { | ||
console.log('CookieManager.getAll =>', res); | ||
}); | ||
|
||
// clear cookies | ||
CookieManager.clearAll() | ||
.then((res) => { | ||
console.log('CookieManager.clearAll =>', res); | ||
}); | ||
|
||
// clear a specific cookie by its name (IOS ONLY) | ||
CookieManager.clearByName('cookie_name') | ||
.then((res) => { | ||
console.log('CookieManager.clearByName =>', res); | ||
}); | ||
|
||
``` | ||
|
||
### WebKit-Support (iOS only) | ||
React Native comes with a WebView component, which uses UIWebView on iOS. Introduced in iOS 8 Apple implemented the WebKit-Support with all the performance boost. | ||
|
||
To use this it's required to use a special implementation of the WebView component (e.g. [react-native-wkwebview](https://github.com/CRAlpha/react-native-wkwebview)). | ||
|
||
This special implementation of the WebView component stores the cookies __not__ in `NSHTTPCookieStorage` anymore. The new cookie-storage is `WKHTTPCookieStore` and implementes a differnt interface. | ||
|
||
To use this _CookieManager_ with WebKit-Support we extended the interface with the attribute `useWebKit` (a boolean value, default: `FASLE`) for the following methods: | ||
|
||
|Method|WebKit-Support|Method-Signature| | ||
|---|---|---| | ||
|getAll| Yes | `CookieManager.getAll(useWebKit:boolean)` | | ||
|clearAll| Yes | `CookieManager.clearAll(useWebKit:boolean)` | | ||
|get| Yes | `CookieManager.get(url:string, useWebKit:boolean)` | | ||
|set| Yes | `CookieManager.set(cookie:object, useWebKit:boolean)` | | ||
|
||
##### Usage | ||
```javascript | ||
import CookieManager from 'react-native-cookie-store'; | ||
|
||
const useWebKit = true; | ||
|
||
// list cookies (IOS ONLY) | ||
CookieManager.getAll(useWebKit) | ||
.then((res) => { | ||
console.log('CookieManager.getAll from webkit-view =>', res); | ||
}); | ||
|
||
// clear cookies | ||
CookieManager.clearAll(useWebKit) | ||
.then((res) => { | ||
console.log('CookieManager.clearAll from webkit-view =>', res); | ||
}); | ||
|
||
// Get cookies as a request header string | ||
CookieManager.get('http://example.com', useWebKit) | ||
.then((res) => { | ||
console.log('CookieManager.get from webkit-view =>', res); | ||
// => 'user_session=abcdefg; path=/;' | ||
}); | ||
|
||
// set a cookie (IOS ONLY) | ||
const newCookie: = { | ||
name: 'myCookie', | ||
value: 'myValue', | ||
domain: 'some domain', | ||
origin: 'some origin', | ||
path: '/', | ||
version: '1', | ||
expiration: '2015-05-30T12:30:00.00-05:00' | ||
}; | ||
|
||
CookieManager.set(newCookie, useWebKit) | ||
.then((res) => { | ||
console.log('CookieManager.set from webkit-view =>', res); | ||
}); | ||
``` | ||
|
Oops, something went wrong.