Skip to content

Commit

Permalink
feat(Android): Add flush method on Android (#64)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Android Minmum SDK bumped to API 21
  • Loading branch information
luancurti authored Jul 24, 2020
1 parent 87129bf commit 74cd6a1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ CookieManager.clearByName('http://example.com', 'cookie_name')
.then((success) => {
console.log('CookieManager.clearByName =>', success);
});

// flush cookies (ANDROID ONLY)
CookieManager.flush()
.then((success) => {
console.log('CookieManager.flush =>', success);
});
```

### WebKit-Support (iOS only)
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import groovy.json.JsonSlurper

def DEFAULT_COMPILE_SDK_VERSION = 29
def DEFAULT_BUILD_TOOLS_VERSION = '29.0.3'
def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_MIN_SDK_VERSION = 21
def DEFAULT_TARGET_SDK_VERSION = 29

def safeExtGet(prop, fallback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ public void setFromResponse(String url, String cookie, final Promise promise) {
addCookies(url, cookie, promise);
}

@ReactMethod
public void flush(Promise promise) {
try {
mCookieManager.flush();
promise.resolve(true);
} catch (Exception e) {
promise.reject(e);
}
}

@ReactMethod
public void getFromResponse(String url, Promise promise) throws URISyntaxException, IOException {
promise.resolve(url);
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ module.exports = {
CookieManager.set(url, cookie, useWebKit),
clearByName: (url, name, useWebKit = false) =>
CookieManager.clearByName(url, name, useWebKit),
flush: async () => {
if (Platform.OS === 'android') {
await CookieManager.flush();
}
},
};

for (var i = 0; i < functions.length; i++) {
Expand Down

0 comments on commit 74cd6a1

Please sign in to comment.