Skip to content

Commit fb0f904

Browse files
Merge pull request #149 from fusioncharts/rel/5.1.0
Added notification module for iOS & Updated README.md
2 parents 3cd699a + 7257b36 commit fb0f904

File tree

2 files changed

+119
-53
lines changed

2 files changed

+119
-53
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
## Deprecation disclaimer :
2-
3-
This is the oldest version of `React Native wrapper` which was released upto 4.1.2 .The project is no longer actively maintained
4-
51
## FusionCharts React Native :
62
A `React Native` component which provides bindings for `FusionCharts` JavaScript Charting Library. It easily adds rich and interactive charts to any `React Native` Projects.
73

@@ -37,7 +33,9 @@ A `React Native` component which provides bindings for `FusionCharts` JavaScript
3733

3834
If you're using this package with Expo Tools, please make sure your Expo SDK version is higher than or equal to `v38.0.0`.
3935

40-
In bare React Native application you need to also install the react-native-unimodules package, and configure the content of ios and android build directiories like it's described [here](https://docs.expo.io/bare/installing-unimodules/#installation).
36+
In bare React Native application you need to also install the expo-modules package, and configure the content of ios and android build directories like it's described [here](https://docs.expo.dev/bare/installing-expo-modules/).
37+
38+
To use the export file in iOS you need to get the file’s storage permission and to get notifications in iOS you need to get notifications permission.
4139

4240
As the original `webview` module will be deprecated from `react-native`, please update `react-native-fusioncharts` and follow the given steps in your project:
4341

src/FusionCharts.js

Lines changed: 116 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
askAsync,
99
MEDIA_LIBRARY_WRITE_ONLY,
1010
NOTIFICATIONS,
11+
getAsync
1112
} from "expo-permissions";
1213
import * as Notifications from "expo-notifications";
1314
import * as Sharing from "expo-sharing";
@@ -88,55 +89,122 @@ export default class ReactNativeFusionCharts extends Component {
8889
};
8990

9091
exportData = async (data) => {
91-
let extension, base64Code;
92-
const { status } = await askAsync(MEDIA_LIBRARY_WRITE_ONLY);
93-
const fileUri = FileSystem.documentDirectory + data.name;
94-
95-
if (status === "granted") {
96-
extension = data.name.substr(data.name.indexOf(".") + 1);
97-
98-
switch (extension) {
99-
case "jpg": {
100-
console.log(data);
101-
base64Code = data.edata.split("data:image/jpeg;base64,")[1];
102-
break;
103-
}
104-
case "png": {
105-
base64Code = data.edata.split("data:image/png;base64,")[1];
106-
break;
107-
}
108-
case "svg": {
109-
base64Code = data.edata.split("data:image/svg+xml;base64,")[1];
110-
break;
111-
}
112-
case "pdf": {
113-
base64Code = data.edata.split("data:application/pdf;base64,")[1];
114-
break;
115-
}
116-
case "csv": {
117-
if (Platform.OS === "ios") {
118-
base64Code = data.edata.split("data:text/csv;base64,")[1];
119-
} else {
120-
base64Code = data.edata.split("data:text/csv;base64;;base64,")[1];
92+
if (Platform.OS === "ios") {
93+
let extension, base64Code;
94+
const { status } = await MediaLibrary.getPermissionsAsync();
95+
const fileUri = FileSystem.documentDirectory + data.name;
96+
97+
if (status === "granted") {
98+
extension = data.name.substr(data.name.indexOf(".") + 1);
99+
100+
switch (extension) {
101+
case "jpg": {
102+
base64Code = data.edata.split("data:image/jpeg;base64,")[1];
103+
break;
104+
}
105+
case "png": {
106+
base64Code = data.edata.split("data:image/png;base64,")[1];
107+
break;
108+
}
109+
case "svg": {
110+
base64Code = data.edata.split("data:image/svg+xml;base64,")[1];
111+
break;
112+
}
113+
case "pdf": {
114+
base64Code = data.edata.split("data:application/pdf;base64,")[1];
115+
break;
116+
}
117+
case "csv": {
118+
if (Platform.OS === "ios") {
119+
base64Code = data.edata.split("data:text/csv;base64,")[1];
120+
} else {
121+
base64Code = data.edata.split("data:text/csv;base64;;base64,")[1];
122+
}
123+
break;
124+
}
125+
case "xlsx": {
126+
base64Code = data.edata.split(
127+
"data:application/vnd.ms-excel;base64,"
128+
)[1];
129+
break;
121130
}
122-
break;
123-
}
124-
case "xlsx": {
125-
base64Code = data.edata.split(
126-
"data:application/vnd.ms-excel;base64,"
127-
)[1];
128-
break;
129131
}
130-
}
131132

132-
FileSystem.writeAsStringAsync(fileUri, base64Code, {
133-
encoding: FileSystem.EncodingType.Base64,
134-
}).then(() => {
135-
if (Platform.OS === "ios") {
133+
FileSystem.writeAsStringAsync(fileUri, base64Code, {
134+
encoding: FileSystem.EncodingType.Base64,
135+
}).then(() => {
136+
136137
Sharing.shareAsync(fileUri);
138+
MediaLibrary.saveToLibraryAsync(fileUri).then(async () => {
139+
await askAsync(NOTIFICATIONS);
140+
141+
Notifications.setNotificationChannelAsync("download", {
142+
name: "download notifications",
143+
sound: "email-sound.wav",
144+
});
145+
146+
Notifications.scheduleNotificationAsync({
147+
content: {
148+
title: `${data.name}`,
149+
body: `Download complete`,
150+
sound: "email-sound.wav",
151+
data: { data: fileUri },
152+
},
153+
trigger: {
154+
seconds: 1,
155+
channelId: "download",
156+
},
157+
});
158+
});
159+
});
160+
} else {
161+
await MediaLibrary.requestPermissionsAsync();
162+
}
163+
} else {
164+
let extension, base64Code;
165+
const { status } = await askAsync(MEDIA_LIBRARY_WRITE_ONLY);
166+
const fileUri = FileSystem.documentDirectory + data.name;
167+
168+
if (status === "granted") {
169+
extension = data.name.substr(data.name.indexOf(".") + 1);
170+
171+
switch (extension) {
172+
case "jpg": {
173+
console.log(data);
174+
base64Code = data.edata.split("data:image/jpeg;base64,")[1];
175+
break;
176+
}
177+
case "png": {
178+
base64Code = data.edata.split("data:image/png;base64,")[1];
179+
break;
180+
}
181+
case "svg": {
182+
base64Code = data.edata.split("data:image/svg+xml;base64,")[1];
183+
break;
184+
}
185+
case "pdf": {
186+
base64Code = data.edata.split("data:application/pdf;base64,")[1];
187+
break;
188+
}
189+
case "csv": {
190+
if (Platform.OS === "ios") {
191+
base64Code = data.edata.split("data:text/csv;base64,")[1];
192+
} else {
193+
base64Code = data.edata.split("data:text/csv;base64;;base64,")[1];
194+
}
195+
break;
196+
}
197+
case "xlsx": {
198+
base64Code = data.edata.split(
199+
"data:application/vnd.ms-excel;base64,"
200+
)[1];
201+
break;
202+
}
137203
}
138204

139-
if (Platform.OS === "android") {
205+
FileSystem.writeAsStringAsync(fileUri, base64Code, {
206+
encoding: FileSystem.EncodingType.Base64,
207+
}).then(() => {
140208
Sharing.shareAsync(fileUri);
141209
MediaLibrary.saveToLibraryAsync(fileUri).then(async () => {
142210
await askAsync(NOTIFICATIONS);
@@ -159,10 +227,10 @@ export default class ReactNativeFusionCharts extends Component {
159227
},
160228
});
161229
});
162-
}
163-
});
164-
} else {
165-
await askAsync(MEDIA_LIBRARY_WRITE_ONLY);
230+
});
231+
} else {
232+
await askAsync(MEDIA_LIBRARY_WRITE_ONLY);
233+
}
166234
}
167235
};
168236

@@ -637,4 +705,4 @@ const styles = StyleSheet.create({
637705
flex: 1,
638706
backgroundColor: "transparent",
639707
},
640-
});
708+
});

0 commit comments

Comments
 (0)