Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ android {
dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")
implementation("com.facebook.react:flipper-integration")
implementation("com.facebook.flipper:flipper-fresco-plugin:0.182.0")

if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
Expand Down
2 changes: 1 addition & 1 deletion Example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext {
buildToolsVersion = "34.0.0"
minSdkVersion = 21
minSdkVersion = 23
compileSdkVersion = 34
targetSdkVersion = 34
ndkVersion = "25.1.8937393"
Expand Down
2 changes: 1 addition & 1 deletion Example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@svgr/webpack": "^8.1.0",
"file-loader": "^6.2.0",
"react": "18.2.0",
"react-native": "^0.73.6",
"react-native": "^0.75.0",
"react-native-macos": "^0.73.0-0",
"react-native-qrcode-svg": "link:../",
"react-native-svg": "^15.5.0",
Expand Down
3,840 changes: 1,888 additions & 1,952 deletions Example/yarn.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ Install dependency packages

```bash
yarn add react-native-svg react-native-qrcode-svg
# For React Native < 0.75 please install `text-encoding` package too!
yarn add text-encoding
```
Or
```bash
npm i -S react-native-svg react-native-qrcode-svg
# For React Native < 0.75 please install `text-encoding` package too!
npm i -S text-encoding
```

If you are using `React Native 0.60.+` go to the folder **your-project/ios** and run `pod install`, and you're done.
Expand Down
24,938 changes: 4,998 additions & 19,940 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-qrcode-svg",
"version": "6.3.12",
"version": "6.4.0",
"description": "A QR Code generator for React Native based on react-native-svg and javascript-qrcode.",
"main": "index.js",
"types": "index.d.ts",
Expand Down Expand Up @@ -52,12 +52,17 @@
"peerDependencies": {
"react": "*",
"react-native": ">=0.63.4",
"react-native-svg": ">=14.0.0"
"react-native-svg": ">=14.0.0",
"text-encoding": "^0.7.0"
},
"peerDependenciesMeta": {
"text-encoding": {
"optional": true
}
},
"dependencies": {
"prop-types": "^15.8.0",
"qrcode": "^1.5.1",
"text-encoding": "^0.7.0"
"qrcode": "^1.5.1"
},
"devDependencies": {
"@types/react": "^18.2.75",
Expand Down
24 changes: 21 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
global.TextEncoder = require("text-encoding").TextEncoder;

import React, { useMemo } from "react";
import { Platform } from "react-native";
import React, { useMemo, useEffect } from "react";
import Svg, {
Defs,
G,
Expand Down Expand Up @@ -102,6 +101,8 @@ const QRCode = ({
onError,
testID,
}) => {
useEffect(loadTextEncodingPolyfill, []);

const result = useMemo(() => {
try {
return transformMatrixIntoPath(genMatrix(value, ecl), size);
Expand Down Expand Up @@ -180,4 +181,21 @@ const QRCode = ({
);
};

function loadTextEncodingPolyfill() {
// Platform.constants isn't available on the web.
const version = Platform.constants?.reactNativeVersion;
if (!global.TextEncoder && version?.major === 0 && version?.minor < 75) {
try {
require.resolve("text-encoding");
import("text-encoding").then((m) => {
global.TextEncoder = m.TextEncoder;
});
} catch (error) {
console.error(
"If you are using RN < 0.75 please install the `text-encoding` library in your project"
);
}
}
}

export default QRCode;
Loading