ionic-team / tutorial-photo-gallery-react Goto Github PK
View Code? Open in Web Editor NEWPhoto Gallery Tutorial: Ionic React and Capacitor
Home Page: https://ionicframework.com/docs/react/your-first-app
License: Other
Photo Gallery Tutorial: Ionic React and Capacitor
Home Page: https://ionicframework.com/docs/react/your-first-app
License: Other
I'm learning ionic+react by ionicframework.com/docs/react and following the steps on Your First Ionic App. After the implementation, it's supose to save the photos, but this is not happening and that's no error on my web console. Can someone help me with this?
Steps I took:
git clone https://github.com/ionic-team/tutorial-photo-gallery-react
npm install
ionic serve
and it works in the browser. Then I do
ionic capacitor copy android
# Complains about cordova plugin not being found if I don't do this first
npm install -g serve
serve -s build
and I've got my gradle build configuration that I then hand off to android studio, which configures and builds the project without errors. When launching on the app on my device, clicking on the camera button does nothing unfortunately.
Logcat shows
2022-03-02 14:59:12.466 11654-11654/io.ionic.starter E/Capacitor/Console: File: http://localhost/static/js/49.e396144e.chunk.js - Line 2 - Msg: Uncaught (in promise) Error: "Camera" plugin is not implemented on android
I'm using ionic 6.18.1.
I tried this solution with npx cap sync android
after deleting the assets and plugin in the android folder as they suggest. Clean project in Android Studio. Having trouble figuring out how to get this app working on android, so I figured I'd ask for help.
Many thanks. 🙏
https://github.com/ionic-team/tutorial-photo-gallery-react/releases/tag/v3.0
When running dev server via npm run start
command, the css style seems broken:
The page should be look like:
git clone https://github.com/ionic-team/tutorial-photo-gallery-react.git
cd tutorial-photo-gallery-react
npm ci
npm run start
http://localhost:3000
Windows 10
Following how to run instructions
Message Files successfully emitted, waiting for typecheck results...
The console hangs and PWA app does not start.
C:\ae\adaept.com\ae-gallery-react>cd C:\ae\tutorial-photo-gallery-react
C:\ae\tutorial-photo-gallery-react>npm i
> [email protected] postinstall C:\ae\tutorial-photo-gallery-react\node_modules\babel-runtime\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"
Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock
Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
> [email protected] postinstall C:\ae\tutorial-photo-gallery-react\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"
> [email protected] postinstall C:\ae\tutorial-photo-gallery-react\node_modules\core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\watchpack\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\jest-haste-map\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
added 1789 packages from 901 contributors and audited 1995 packages in 98.387s
58 packages are looking for funding
run `npm fund` for details
found 4954 vulnerabilities (4948 low, 6 high)
run `npm audit fix` to fix them, or `npm audit` for details
C:\ae\tutorial-photo-gallery-react>ionic serve
> react-scripts.cmd start
[react-scripts] i 「wds」: Project is running at http://192.168.86.83/
[react-scripts] i 「wds」: webpack output is served from
[react-scripts] i 「wds」: Content not from webpack is served from C:\ae\tutorial-photo-gallery-react\public
[react-scripts] i 「wds」: 404s will fallback to /
[react-scripts] Starting the development server...
[react-scripts]
[react-scripts] Browserslist: caniuse-lite is outdated. Please run:
[react-scripts] npx browserslist@latest --update-db
[react-scripts] Files successfully emitted, waiting for typecheck results...
Ionic Info
C:\ae\tutorial-photo-gallery-react>ionic info
Ionic:
Ionic CLI : 6.11.12 (C:\Users\peter\AppData\Roaming\npm\node_modules\@ionic\cli)
Ionic Framework : @ionic/react 5.0.7
Capacitor:
Capacitor CLI : 2.0.1
@capacitor/core : 2.0.1
Utility:
cordova-res : 0.15.1
native-run : 1.2.1
System:
NodeJS : v12.18.3 (C:\Program Files\nodejs\node.exe)
npm : 6.13.4
OS : Windows 10
C:\ae\tutorial-photo-gallery-react>
The project is runnig at http://192.168.86.83/
Open the URL and get:
Cloned repo with no changes:
https://github.com/peterennis/tutorial-photo-gallery-react
Possibly related - same emitting problem:
When running this on iOS, the gallery does not work reliably. If you save a couple of photos, close the app, restart it and add another photo, then some of the existing ones are replaced by the new ones. How come?
When a user opens camera but closes it by the top left X button, it throws Error: User cancelled photos app
and crashes the PWA app.
This takePhoto function have to use a try catch.
When following the tutorial
I noticed we are importing Filesystem but the code given shows FileSystem.
export function usePhotoGallery()
const savePicture = async (photo: CameraPhoto, fileName: string): Promise<Photo> => {
const base64Data = await base64FromPath(photo.webPath!);
const savedFile = await FileSystem.writeFile({
path: fileName,
data: base64Data,
directory: Directory.Data
});
// Use webPath to display the new image instead of base64 since it's
// already loaded into memory
return {
filepath: fileName,
webviewPath: photo.webPath
};
};
}
...
}
I've got the demo working on the desktop browser - that is when i click the camera button i get the popup confirming access to the webcam - i can then take photos and everything works as normal.
Trying the same on android (Chrome) and iOS (also Chrome) the button appears to do nothing.
i tried removing the call to defineCustomElements
to see what effect that has and i then do get an error message as expected so it seems it is doing something but not enough to get it working
I got this error right after create the project with ionic start
and using the template my-first-app
. I saw that the builder clone this repo, so that's why I created this issue here.
valdinei@ideapad:~/dev/ionic-test$ ionic serve
> react-scripts start
[react-scripts] ℹ 「wds」: Project is running at http://172.25.17.254/
[react-scripts] ℹ 「wds」: webpack output is served from
[react-scripts] ℹ 「wds」: Content not from webpack is served from /home/valdinei/dev/ionic-test/public
[react-scripts] ℹ 「wds」: 404s will fallback to /
[react-scripts] Starting the development server...
[react-scripts]
[react-scripts] Error: error:0308010C:digital envelope routines::unsupported
[react-scripts] at new Hash (node:internal/crypto/hash:71:19)
[react-scripts] at Object.createHash (node:crypto:133:10)
[react-scripts] at module.exports (/home/valdinei/dev/ionic-test/node_modules/webpack/lib/util/createHash.js:135:53)
[react-scripts] at NormalModule._initBuildHash (/home/valdinei/dev/ionic-test/node_modules/webpack/lib/NormalModule.js:417:16)
[react-scripts] at handleParseError (/home/valdinei/dev/ionic-test/node_modules/webpack/lib/NormalModule.js:471:10)
[react-scripts] at /home/valdinei/dev/ionic-test/node_modules/webpack/lib/NormalModule.js:503:5
[react-scripts] at /home/valdinei/dev/ionic-test/node_modules/webpack/lib/NormalModule.js:358:12
[react-scripts] at /home/valdinei/dev/ionic-test/node_modules/loader-runner/lib/LoaderRunner.js:373:3
[react-scripts] at iterateNormalLoaders (/home/valdinei/dev/ionic-test/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
[react-scripts] at iterateNormalLoaders (/home/valdinei/dev/ionic-test/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
[react-scripts] /home/valdinei/dev/ionic-test/node_modules/react-scripts/scripts/start.js:19
[react-scripts] throw err;
[react-scripts] ^
[react-scripts] Error: error:0308010C:digital envelope routines::unsupported
[react-scripts] at new Hash (node:internal/crypto/hash:71:19)
[react-scripts] at Object.createHash (node:crypto:133:10)
[react-scripts] at module.exports (/home/valdinei/dev/ionic-test/node_modules/webpack/lib/util/createHash.js:135:53)
[react-scripts] at NormalModule._initBuildHash (/home/valdinei/dev/ionic-test/node_modules/webpack/lib/NormalModule.js:417:16)
[react-scripts] at /home/valdinei/dev/ionic-test/node_modules/webpack/lib/NormalModule.js:452:10
[react-scripts] at /home/valdinei/dev/ionic-test/node_modules/webpack/lib/NormalModule.js:323:13
[react-scripts] at /home/valdinei/dev/ionic-test/node_modules/loader-runner/lib/LoaderRunner.js:367:11
[react-scripts] at /home/valdinei/dev/ionic-test/node_modules/loader-runner/lib/LoaderRunner.js:233:18
[react-scripts] at context.callback (/home/valdinei/dev/ionic-test/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
[react-scripts] at /home/valdinei/dev/ionic-test/node_modules/babel-loader/lib/index.js:59:103 {
[react-scripts] opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
[react-scripts] library: 'digital envelope routines',
[react-scripts] reason: 'unsupported',
[react-scripts] code: 'ERR_OSSL_EVP_UNSUPPORTED'
[react-scripts] }
[react-scripts] Node.js v18.12.1
I searched and I saw that's probably the old webpack version, that use the old SSL algorithm, but the new Node versions already use a new algorithm.
In case anyone experiences the issue on page two of trying to capture a photo after first setting up the usePhotoGallery()
hook and clicking the photo button for the first time. You may see the following in your console related to loading the pwa-camera-modal:
The way to resolve this issue is to go into your vite.config.ts
and remove the section for the test and replace it with this:
//Remove:
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/setupTests.ts',
}
//Replace with:
optimizeDeps: {
exclude: ['@ionic/pwa-elements/loader']
}
Your config file should now look like this:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
optimizeDeps: {
exclude: ['@ionic/pwa-elements/loader']
}
})
This is a known issue in vite: vitejs/vite#12434
You may need to delete your node_modules folder and install again.
Get the below type error after upgrade to React 18,
Type '{ children: Element; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<IonReactRouter> & Readonly<IonReactRouterProps>'
is there any work around
While following the tutorial in t3rd step, saving photos, the code gives an error.
const takePhoto = async () => {
const cameraPhoto = await Camera.getPhoto({
resultType: CameraResultType.Uri,
source: CameraSource.Camera,
quality: 100
});
const fileName = new Date().getTime() + '.jpeg';
const savedFileImage = await savePicture(cameraPhoto, fileName);
const newPhotos = [savedFileImage, ...photos];
setPhotos(newPhotos);
};
setPhotos(newPhotos);
gives an error because they aren't the same type.
Argument of type '(UserPhoto | Photo)[]' is not assignable to parameter of type 'SetStateAction<UserPhoto[]>'.
The code in this repo has the correct code. The solution:
Change the return type this line in the docs:
const savePicture = async (photo: Photo, fileName: string): Promise
To this one:
const savePicture = async (photo: Photo, fileName: string): Promise<UserPhoto>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.