How to use react-native-pan-zoom with react native web - react-native-web

I have a react native web app with an Image. I want to do pan and zoom so I tried wrapping it with ImageZoom from the react-native-pan-zoom module.
<ImageZoom
cropWidth={Dimensions.get('window').width}
cropHeight={Dimensions.get('window').height}
imageWidth={200}
imageHeight={200}
>
<Image source={`/EventMaps/${name}`} style={styles.image} resizeMode="center" />
</ImageZoom>
But a get a compile error
./node_modules/react-native-image-pan-zoom/built/image-zoom/image-zoom.component.js
Module parse failed: Unexpected token (555:16)
You may need an appropriate loader to handle this file type.
| ]
| };
| return (<react_native_1.View style={__assign({}, image_zoom_style_1.default.container, this.props.style, { width: this.props.cropWidth, height: this.props.cropHeight })}
{...this.imagePanResponder.panHandlers}>
| <react_native_1.Animated.View style={animateConf}>
| <react_native_1.View onLayout={this.handleLayout.bind(this)} style={{
Should this work??

Third-party libs in node_modules are often excluded from being transformed in web projects, since they are usually shipped with compiled dist file. But many react-native libs are shipped with source jsx file because it should be loaded and transformed by react-native toolchain.
In this case, you should explicitly add the specific lib to include option of babel or webpack config. See the react-native-web document for an example:
path.resolve(appDirectory, 'node_modules/react-native-uncompiled')
In your case react-native-image-pan-zoom instead of react-native-uncompiled.
However, it cannot guarantee react-native-image-pan-zoom can be used in your web project, since many react-native libs use some features react-native-web didn't polyfilled, or contain native extensions. You may take a deep look after successfully loading those files.

Related

Running Cypress tests with TailwindCSS 3

I've been running my component tests via cypress open-ct for a while now, relying on importing /node_modules/tailwindcss/dist/tailwindcss.min.css.
Since upgrading to Tailwind v3 some of my tests are failing as there is no prebuilt CSS file I can import - everything is generated just in time.
For example, testing if a modal closes when clicking on a overlay that is fixed and full width fails as the whole modal is rendered so that it is inaccessible by Cypress.
Another side-issue that stems from not having access to Tailwind classes is that videos recorded when running tests in CI are unusable as they are just a bunch of random native elements.
I've been importing Tailwind like this at the top of each Test file (before describes)
import { mount } from '#cypress/vue'
import '/node_modules/tailwindcss/dist/tailwind.min.css'
import MultiSelectField from './MultiSelectField.vue'
import { ref } from "vue";
Any ideas how to include Tailwind (preferably globally) so tests won't fail?
You can use the Tailwind CLI to generate your stylesheet on the fly.
Add this plugin in cypress/plugins/tailwind.js (be sure to change the -i source from ./src/styles/globals.css to your base CSS file):
before(() => {
cy.exec('npx tailwindcss -i ./src/styles/globals.css -m').then(
({ stdout }) => {
if (!document.head.querySelector('#tailwind-style')) {
const link = document.createElement('style')
link.id = 'tailwind-style'
link.innerHTML = stdout
document.head.appendChild(link)
}
},
)
})
Then, load the plugin by importing it in cypress/support/index.js:
import '../plugins/tailwind'
You should also set up a separate config file for your component tests, such as cypress/support/component.js, and specify that in your cypress.json config file:
{
"component": {
"supportFile": "cypress/support/component.js",
},
"e2e": {
"supportFile": "cypress/support/e2e.js"
}
}
Then, only include import '../plugins/tailwind' in your cypress/support/component.js config file, so that you don't perform the JIT compilation for your E2E tests (since it's unnecessary).
Michael Hays' solution works, but it rebuilds the whole .css file every time changes to the code are made, which slows tests down. An alternative would be to run tailwind externally in watch mode.
npm i -D concurrently
package.json
"scripts": {
"test": "concurrently \"tailwindcss -i ./src/index.css -o ./dist/index.css --watch\" \"cypress open\" "
},
cypress/support/component.ts
import "../../dist/index.css";
I see you're using import '/node_modules/tailwindcss/dist/tailwind.min.css' which expects a pre-compiled bundle. If you have any customization added to the tailwind config, those would not be covered.
But if you can't use the generated css and don't have any tailwind customization, you could use the cdn version from https://cdn.tailwindcss.com/
Because you are running it in a test and don't want to add to possible "flakyness" of using remote dependency, you'll likely want to download that file and keep it in the repo and update it manually from time to time. You can also use some automation for getting the correct version from the cdn before running the test, but Ideally you'd use the generated css, since that's what you're shipping so that's the resource that should be getting tested.

Build fails with resolve errors

I am trying to setup socket.io-client inside a svelte component.
The docs say that I can do import { io } from 'socket.io-client'.
But when I try to run the app using the serve target, the command fails with the following logs:
Bundle complete. Watching for file changes...
Bundling...
'bufferutil' is imported by bufferutil?commonjs-external, but could not be resolved – treating it as an external dependency
'utf-8-validate' is imported by utf-8-validate?commonjs-external, but could not be resolved – treating it as an external dependency
Circular dependency: node_modules\util\util.js -> node_modules\util\node_modules\inherits\inherits.js -> node_modules\util\util.js
Circular dependency: node_modules\util\util.js -> node_modules\util\node_modules\inherits\inherits.js -> C:\Users\munda\Documents\upwork\upwork-gameshow\node_modules\util\util.js?commonjs-proxy -> node_modules\util\util.js
#rollup/plugin-typescript: Rollup 'sourcemap' option must be set to generate source maps.
No name was provided for external module 'tty' in output.globals – guessing 'tty'
No name was provided for external module 'os' in output.globals – guessing 'os'
No name was provided for external module 'fs' in output.globals – guessing 'fs'
No name was provided for external module 'child_process' in output.globals – guessing 'require$$0'
No name was provided for external module 'http' in output.globals – guessing 'require$$1'
No name was provided for external module 'https' in output.globals – guessing 'require$$2'
No name was provided for external module 'net' in output.globals – guessing 'net'
No name was provided for external module 'tls' in output.globals – guessing 'tls'
No name was provided for external module 'crypto' in output.globals – guessing 'require$$0$3'
No name was provided for external module 'zlib' in output.globals – guessing 'zlib'
No name was provided for external module 'bufferutil' in output.globals – guessing 'require$$1$1'
No name was provided for external module 'stream' in output.globals – guessing 'require$$0$2'
No name was provided for external module 'utf-8-validate' in output.globals – guessing 'require$$0$1'
Creating a browser bundle that depends on Node.js built-in modules ("tty", "os", "http", "https", "zlib" and "stream"). You might need to include https://github.com/snowpackjs/rollup-plugin-polyfill-node
Steps I took to generate the app:
Initiate an nx-workspace using yarn create nx-workspace
Install the svelte generators using yarn add #nxext/svelte, link: https://nx.dev/community#:~:text=the%20Nx%20workflow-,%40nxext/svelte,-Nx%20plugin%20to
Generate a svelte application using the installed generator.
Add the socket.io client side code in the component (basic socket initialisation as mentioned in docs).
Since my server and client are not going to be hosted on the same domain, add the import { io } from 'socket.io-client' and initialize the socket using const socket = io(SERVER_URL)(in my case this was http://localhost:3000)
Install socket.io client using yarn socket.io-client.
Run the serve target using nx run-many --target=serve --all --parallel, fingers crossed.
Result: The above mentioned log.
What am I missing?
I needed to install the following missing dependencies:
bufferutil
utf-8-validate
A simple yarn add bufferutil utf-8-validate fixed it for me. This is mentioned in docs for socket.io-client package or socket.io official documentation website.
This did fix builds on my PC (windows) but I could not get the same thing running on mac. I tried deleting node_modules and yarn.lock, re-running yarn.
Finally I had to go through the CDN route.
This is how I did it:
Move the socket initialisation logic in a function.
<script>
...
const initialiseSocket = () => {
socket = io('http://localhost:3000');
socket.on('messages', (data) => {
//...
});
}
</script>
Add a svelte:head tag to load the socket-io.client from CDN and pass the function to this script's on:load.
<svelte:head>
<script
src="https://cdn.socket.io/4.2.0/socket.io.min.js"
integrity="sha384-PiBR5S00EtOj2Lto9Uu81cmoyZqR57XcOna1oAuVuIEjzj0wpqDVfD0JA9eXlRsj"
crossorigin="anonymous"
on:load={initialiseSocket}></script>
</svelte:head>

Use SCSS style files within AngularDart 5 and Dart 2

I’m working with Dart 2 and AngularDart 5.
⚠ I searched online about my question, but I didn’t find a satisfactory answer.
❔ Can somebody explain all the steps I need to include and to work with SCSS style files within my AngularDart application?
I started with quickstart application that you can find here.
Thank you!
Add a dev dependency to your pubspec.yaml for sass_builder:
^2.0.0.
Run pub get to download the new dependencies.
Create a sass file ex: lib/app_component.scss and add some styles to it.
Add a the compiled css stylesheet to your the #Component annotation in lib/app_component.dart:
styleUrls: const ['app_component.css'],
The css file will be generated by sass_builder during the build process.
If you are using angluar_components. One could simply turn it on:
Create a build.yaml file with the following content :
targets:
$default:
builders:
angular_components|scss_builder:
enabled: True
Use the following convention for the styleUrl annotations:
styleUrls: const ['app_component.scss.css']
Write your sass in the *.scss files.
With newest versions:
Surprise: In styleUrls are in a different CSS filename (not with the .scss.css extension, just .css; e.g. app_component.css, but the styles are in app_component.scss).
Surprise: In app_component.scss, import without lib in the path:
#import 'package:angular_components/app_layout/mixins';
I am using this command:
pub run build_runner serve --verbose
See with package info:
https://github.com/dart-lang/angular_components/issues/374#issuecomment-636344237

error makeNodePromisified is not a function when bundling bluebird with webpack

When I bundle bluebird with webpack and target node I'm getting the following error -
makeNodePromisified(key, THIS, key, fn, suffix, multiArgs);
^
TypeError: makeNodePromisified is not a function
at promisifyAll (...)
at Function.e.24.module.exports.Promise.promisifyAll (...)
It appears to be pulling in ./node_modules/bluebird/browser/bluebird.js which has __BROWSER__ replaced with true. How do I pull in the non-browser version?
Don't pull bluebird directly from webpack, the source isn't designed to work this way because of optimizations performed.
Instead, include the minfieid result and set an alias to the minified end-result file:
externals: {
"Promise": "Promise"
}
In your Webpack configuration file. Alternatively you can ignore it as suggested here if you don't need the type feedback (not using TypeScript for instance).

Add angular-material to mean.io app

I'm trying to add angular-material to a mean.io application.
I have, in my custom package, used bower to install angular-material and now I have a .../public/assets/lib/angular-material folder.
So far so good. Now I want to use it in my custom mean.io module and according to their documentation I have added
MyPackage.angularDependencies(['ngMaterial']);
in my app.js file.
I have also aggregated angular-material.css and angular-material.js (not sure if this should be needed).
But, I get the following error:
Failed to instantiate module mean due to:
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=m...)
at Error (native)
at http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:6:416
at http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:38:391
at n (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:7:333)
at g (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:37:488)
at http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:38:134
at n (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:7:333)
at g (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:37:488)
at eb (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:41:249)
at c (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:19:463
I'm assuming mean doesn't find the angular-material module and I need to specify its path somewhere. But I can't figure out where.
I had the same problem, this is happening because angular couldn't resolve some required libraries by material, I didn't get so deep into this investigation but I found an alternative solution as described below:
Navigate to the project root directory and then install angular material using bower:
$ bower install angular-material --save
Then, into the project root directory you will find the /config/assets.json file where AngularJS is included, now you add the angular material libraries like this:
{
"core": {
"css": {
"bower_components/build/css/dist.min.css": [
"bower_components/angular/angular-csp.css",
-> "bower_components/angular-material/angular-material.css",
"bower_components/angular-ui-select/dist/select.min.css"
]
},
"js": {
"bower_components/build/js/dist.min.js": [
"bower_components/jquery/dist/jquery.min.js",
"bower_components/angular/angular.min.js",
-> "bower_components/angular-aria/angular-aria.js",
-> "bower_components/angular-animate/angular-animate.js",
-> "bower_components/angular-material/angular-material.js",
"bower_components/angular-mocks/angular-mocks.js",
"bower_components/angular-cookies/angular-cookies.min.js",
"bower_components/angular-resource/angular-resource.min.js",
"bower_components/angular-sanitize/angular-sanitize.min.js",
"bower_components/angular-ui-router/release/angular-ui-router.min.js",
"bower_components/angular-jwt/dist/angular-jwt.min.js",
"bower_components/angular-bootstrap/ui-bootstrap-tpls.js",
"bower_components/angular-ui-select/dist/select.min.js",
"bower_components/web-bootstrap/index.js"
]
}
}
}
I know mean.io says to not alter the core packages, but I didin't find another way to make it work, if anybody has a better solution, please tell us.

Resources