Skip to content

Commit 2799518

Browse files
authored
Merge pull request #176 from numandev1/refactor/kotlin-swift
refactor: convert java to kotlin and objectivec to swift
2 parents 314b865 + 719e864 commit 2799518

File tree

92 files changed

+5643
-4491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+5643
-4491
lines changed

.github/workflows/build-android.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,34 @@ name: Build Android App
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77
paths:
88
- '.github/workflows/build-android.yml'
99
- 'android/**'
1010
- 'example/android/**'
1111
- 'yarn.lock'
1212
- 'example/yarn.lock'
13+
- 'src/Spec/**'
1314
pull_request:
1415
paths:
1516
- '.github/workflows/build-android.yml'
1617
- 'android/**'
1718
- 'example/android/**'
1819
- 'yarn.lock'
1920
- 'example/yarn.lock'
21+
- 'src/Spec/**'
2022

2123
jobs:
22-
build:
24+
build_example:
2325
name: Build Android Example App
2426
runs-on: ubuntu-latest
25-
defaults:
26-
run:
27-
working-directory: example/android
2827
steps:
2928
- uses: actions/checkout@v2
3029

31-
- name: Setup JDK 1.8
30+
- name: Setup JDK 11
3231
uses: actions/setup-java@v1
3332
with:
34-
java-version: 1.8
33+
java-version: 11
3534

3635
- name: Get yarn cache directory path
3736
id: yarn-cache-dir-path
@@ -44,8 +43,10 @@ jobs:
4443
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
4544
restore-keys: |
4645
${{ runner.os }}-yarn-
46+
- name: Install node_modules
47+
run: yarn install --frozen-lockfile
4748
- name: Install node_modules for example/
48-
run: yarn install --frozen-lockfile --cwd ..
49+
run: yarn install --frozen-lockfile --cwd example
4950

5051
- name: Restore Gradle cache
5152
uses: actions/cache@v2
@@ -56,5 +57,5 @@ jobs:
5657
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
5758
restore-keys: |
5859
${{ runner.os }}-gradle-
59-
- name: Run Gradle Build
60-
run: ./gradlew assembleDebug
60+
- name: Run Gradle Build for example/android/
61+
run: cd example/android && ./gradlew assembleDebug --build-cache && cd ../..

.github/workflows/build-ios.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ on:
99
- 'ios/**'
1010
- '*.podspec'
1111
- 'example/ios/**'
12+
- 'src/Spec/**'
1213
pull_request:
1314
paths:
1415
- '.github/workflows/build-ios.yml'
1516
- 'ios/**'
1617
- '*.podspec'
1718
- 'example/ios/**'
19+
- 'src/Spec/**'
1820

1921
jobs:
2022
build:
@@ -40,10 +42,14 @@ jobs:
4042
- name: Install node_modules for example/
4143
run: yarn install --frozen-lockfile --cwd ..
4244

45+
- name: Restore buildcache
46+
uses: mikehardy/buildcache-action@v1
47+
continue-on-error: true
48+
4349
- name: Setup Ruby (bundle)
4450
uses: ruby/setup-ruby@v1
4551
with:
46-
ruby-version: 2.6
52+
ruby-version: 2.7
4753
bundler-cache: true
4854
working-directory: example/ios
4955

@@ -58,13 +64,17 @@ jobs:
5864
restore-keys: |
5965
${{ runner.os }}-pods-
6066
- name: Install Pods
61-
run: bundle exec pod check || bundle exec pod install
67+
run: bundle exec pod check || NO_FLIPPER=1 RCT_NEW_ARCH_ENABLED=1 bundle exec pod install
68+
- name: Install xcpretty
69+
run: gem install xcpretty
6270
- name: Build App
63-
run: "xcodebuild \
71+
run: "set -o pipefail && xcodebuild \
72+
CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ \
73+
-derivedDataPath build -UseModernBuildSystem=YES \
6474
-workspace CompressorExample.xcworkspace \
6575
-scheme CompressorExample \
6676
-sdk iphonesimulator \
6777
-configuration Debug \
68-
-destination \"generic/platform=iOS Simulator\" \
78+
-destination 'platform=iOS Simulator,name=iPhone 11 Pro' \
6979
build \
70-
CODE_SIGNING_ALLOWED=NO"
80+
CODE_SIGNING_ALLOWED=NO | xcpretty"

.github/workflows/validate-android.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ jobs:
2020
runs-on: ubuntu-latest
2121
defaults:
2222
run:
23-
working-directory: ./android
23+
working-directory: ./example/android
2424
steps:
2525
- uses: actions/checkout@v2
26-
- name: Setup JDK 1.8
26+
- name: Setup JDK 11
2727
uses: actions/setup-java@v1
2828
with:
29-
java-version: 1.8
29+
java-version: 11
3030

3131
- name: Get yarn cache directory path
3232
id: yarn-cache-dir-path
@@ -40,6 +40,8 @@ jobs:
4040
restore-keys: |
4141
${{ runner.os }}-yarn-
4242
- name: Install node_modules
43+
run: yarn install --frozen-lockfile --cwd ../..
44+
- name: Install node_modules for example/
4345
run: yarn install --frozen-lockfile --cwd ..
4446

4547
- name: Restore Gradle cache
@@ -52,9 +54,9 @@ jobs:
5254
restore-keys: |
5355
${{ runner.os }}-gradle-
5456
- name: Run Gradle Lint
55-
run: ./gradlew lint
57+
run: ./gradlew lint --build-cache
5658

5759
- name: Parse Gradle Lint Report
58-
uses: yutailang0119/action-android-lint@v1.0.2
60+
uses: yutailang0119/action-android-lint@v3.1.0
5961
with:
60-
xml_path: android/build/reports/lint-results.xml
62+
report-path: example/android/build/reports/lint-results.xml

.prettierrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
bracketSpacing: true,
3+
bracketSameLine: true,
4+
singleQuote: true,
5+
trailingComma: 'all',
6+
semi: true,
7+
tabWidth: 2,
8+
useTabs: false,
9+
printWidth: 140,
10+
};

README.md

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
**REACT-NATIVE-COMPRESSOR** is a react-native package, which helps us to Compress `Image`, `Video`, and `Audio` before uploading, same like **Whatsapp** without knowing the compression `algorithm`
1818

1919
<div align="center">
20-
<img height="90" src="/media/whatsapp_logo.png"/>
21-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
22-
<img height="90" src="/media/compress_media.png"/>
20+
<pre>
21+
<img height="90" src="/media/whatsapp_logo.png"/> <img height="90" src="/media/compress_media.png"/>
22+
</pre>
2323
<h2 align="center">🗜️Compress Image, Video, and Audio same like Whatsapp</h2>
2424
</div>
2525

@@ -53,9 +53,7 @@ We should use **react-native-compressor** instead of **FFmpeg** because **react-
5353
<summary>Open Table of Contents</summary>
5454

5555
- [Installation](#installation)
56-
- [For React Native](#react-native)
57-
- [For React Native<0.65](#for-react-native065)
58-
- [For React Native 0.65 or greater](#for-react-native-065-or-greater)
56+
- [For React Native](#Installation)
5957
- [Managed Expo](#managed-expo)
6058
- [Usage](#usage)
6159
- [Image](#image)
@@ -69,6 +67,7 @@ We should use **react-native-compressor** instead of **FFmpeg** because **react-
6967
- [Video Api Docs](#video-1)
7068
- [Audio](#audio)
7169
- [Background Upload](#background-upload)
70+
- [Download File](#download)
7271

7372
* [Other Utilities](#api)
7473
- [Background Upload](#background-upload-1)
@@ -164,6 +163,7 @@ import { Image } from 'react-native-compressor';
164163
const result = await Image.compress('file://path_of_file/image.jpg');
165164
// OR
166165
const result = await Image.compress('https://path_of_file/image.jpg', {
166+
progressDivider: 10,
167167
downloadProgress: (progress) => {
168168
console.log('downloadProgress: ', progress);
169169
},
@@ -204,6 +204,7 @@ const result = await Video.compress(
204204
const result = await Video.compress(
205205
'https://example.com/video.mp4',
206206
{
207+
progressDivider: 10,
207208
downloadProgress: (progress) => {
208209
console.log('downloadProgress: ', progress);
209210
},
@@ -288,6 +289,16 @@ const uploadResult = await backgroundUpload(
288289
);
289290
```
290291

292+
### Download File
293+
294+
```js
295+
import { download } from 'react-native-compressor';
296+
297+
const downloadFileUrl = await download(url, (progress) => {
298+
console.log('downloadProgress: ', progress);
299+
});
300+
```
301+
291302
# API
292303

293304
## Image
@@ -308,6 +319,10 @@ const uploadResult = await backgroundUpload(
308319

309320
it is callback, only trigger when we pass image url from server
310321

322+
- ##### `progressDivider?: number` (default: 0)
323+
324+
we uses it when we use downloadProgress
325+
311326
- ###### `maxWidth: number` (default: 1280)
312327

313328
The maximum width boundary used as the main boundary in resizing a landscape image.
@@ -348,6 +363,10 @@ const uploadResult = await backgroundUpload(
348363

349364
it is callback, only trigger when we pass image url from server
350365

366+
- ##### `progressDivider?: number` (default: 0)
367+
368+
we uses it when we use downloadProgress/onProgress
369+
351370
- ###### `maxSize: number` (default: 640)
352371

353372
The maximum size can be height in case of portrait video or can be width in case of landscape video.
@@ -376,7 +395,7 @@ const uploadResult = await backgroundUpload(
376395

377396
## Background Upload
378397

379-
- ###### `backgroundUpload: (url: string, fileUrl: string, options: FileSystemUploadOptions, onProgress?: ((writtem: number, total: number) => void) | undefined) => Promise<any>
398+
- ###### backgroundUpload: (url: string, fileUrl: string, options: FileSystemUploadOptions, onProgress?: ((writtem: number, total: number) => void) | undefined) => Promise< any >
380399

381400
- ###### ` FileSystemUploadOptions`
382401

@@ -398,6 +417,10 @@ type FileSystemUploadOptions = (
398417
};
399418
```
400419

420+
### Download
421+
422+
- ##### download: ( fileUrl: string, downloadProgress?: (progress: number) => void, progressDivider?: number ) => Promise< string >
423+
401424
### Get Metadata Of Video
402425

403426
if you want to get metadata of video than you can use this function

android/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
buildscript {
2+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
3+
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["Compressor_kotlinVersion"]
4+
25
repositories {
36
google()
47
mavenCentral()
58
}
69

710
dependencies {
811
classpath "com.android.tools.build:gradle:7.2.1"
12+
// noinspection DifferentKotlinGradleVersion
13+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
914
}
1015
}
1116

@@ -14,6 +19,7 @@ def isNewArchitectureEnabled() {
1419
}
1520

1621
apply plugin: "com.android.library"
22+
apply plugin: "kotlin-android"
1723

1824

1925
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
@@ -96,12 +102,14 @@ repositories {
96102
google()
97103
}
98104

105+
def kotlin_version = getExtOrDefault("kotlinVersion")
99106

100107
dependencies {
101108
// For < 0.71, this will be from the local maven repo
102109
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
103110
//noinspection GradleDynamicVersion
104111
implementation "com.facebook.react:react-native:+"
112+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
105113
implementation 'io.github.lizhangqu:coreprogress:1.0.2'
106114
implementation 'com.github.numandev1:VideoCompressor:1a262bba37'
107115
}

0 commit comments

Comments
 (0)