Skip to content

Commit

Permalink
Image cropper
Browse files Browse the repository at this point in the history
  • Loading branch information
duogenesis committed Jan 21, 2024
1 parent 67d4bf6 commit 93fefef
Show file tree
Hide file tree
Showing 9 changed files with 503 additions and 90 deletions.
2 changes: 2 additions & 0 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { login, logout } from './xmpp/xmpp';
import { STATUS_URL } from './env/env';
import { delay } from './util/util';
import { ReportModal } from './components/report-modal';
import { ImageCropper } from './components/image-cropper';

// TODO: iOS UI testing
// TODO: Add the ability to reply to things (e.g. pictures, quiz responses) from people's profiles. You'll need to change the navigation to make it easier to reply to things. Consider breaking profiles into sections which can be replied to, each having one image or block of text. Letting people reply to specific things on the profile will improve intro quality.
Expand Down Expand Up @@ -339,6 +340,7 @@ const App = () => {
</NavigationContainer>
}
<ReportModal/>
<ImageCropper/>
<WebSplashScreen loading={isLoading}/>
</>
);
Expand Down
48 changes: 4 additions & 44 deletions api/api.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import {
Platform,
} from 'react-native';
import {
API_URL,
} from '../env/env';
import * as _ from "lodash";
import { sessionToken } from '../kv-storage/session-token';
import { Buffer } from "buffer";
import { NonNullImageCropperOutput } from '../components/image-cropper';

const SUPPORTED_API_VERSIONS = [3];

Expand Down Expand Up @@ -94,52 +98,8 @@ const japi = async (
return await api(method, endpoint, init);
};

const mapi = async (
method: string,
endpoint: string,
filename: string,
pathOrBase64: string
): Promise<ApiResponse> => {

const formData = (() => {
const formData = new FormData();

if (pathOrBase64.startsWith('file://')) {
// If we're on a mobile device, Expo will provide a path to a file.
formData.append(
filename,
{
uri: pathOrBase64,
name: filename,
type: 'image/jpg',
} as any
);
} else {
// If we're on a web browser device, Expo will provide a base64-encoded
// string.
const base64Data = pathOrBase64.split(',')[1];
const binary = atob(base64Data);
const array = new Uint8Array(binary.length);
for (var i = 0; i < binary.length; i++) {
array[i] = binary.charCodeAt(i);
}
const blob = new Blob([array], { type: 'application/octet-stream' });
formData.append(filename, blob);
}

return formData;
})();

const init = {
body: formData,
};

return await api(method, endpoint, init);
};

export {
SUPPORTED_API_VERSIONS,
api,
japi,
mapi,
};
Loading

0 comments on commit 93fefef

Please sign in to comment.