You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-20Lines changed: 24 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,18 +86,22 @@ Margin for the title and legend will be subtracted from the final width and heig
86
86
87
87
### Functions
88
88
89
-
The uPlot options can include custom functions for things like drawing and formatting tick labels. You'll need to duplicate each function: one as a normal javascript function and another as a string for the webview. Pass any functions to the `functions` prop of `ChartUPlot`, which will be injected into the webview and can be used in the uPlot options.
89
+
If you have custom functions within your uPlot `options`, have them defined elsewhere; do not use inline functions. Then to make use of them on iOS and Android version, wrap all functions into a single string to pass them to the ChartUPlot's `injectedJavaScript` prop.
- One of the other functions passed to the `functions` prop.
130
-
- A global variable that is defined in the webview.
129
+
- One of the other functions passed to the `injectedJavaScript` prop.
130
+
- Anything globally available within a WebView.
131
131
- A function from the uPlot library that is available in the webview.
132
132
133
133
#### Why is it done this way?
134
134
135
-
There may be a better way to do this, so please open an issue if you have a suggestion. Passing javascript functions to the webview is tricky, so the current solution is to pass them as strings into WebView's `injectedJavaScript` prop. This means if you're also supporting web, you need to duplicate each function to support both web and iOS/Android. If you didn't do this and instead tried doing something like `function.toString()`in an iOS build, it does not return the javascript source code.
135
+
There may be a better way to do this, so please open an issue if you have a suggestion. Passing javascript functions to the webview is tricky, so the current solution is to pass them as strings into WebView's `injectedJavaScript` prop. This means if you're also supporting web, you need to duplicate each function to support both web and iOS/Android. You could argue that you can try something like,`function.toString()`, but in iOS build `toString()` does not actually return the javascript source code, so it won't work.
136
136
137
137
## Demo app
138
138
@@ -152,6 +152,10 @@ npx expo run:ios
152
152
eas build --profile development --platform ios --local
153
153
```
154
154
155
+
## Tips
156
+
157
+
1. Don't create inline props to the `ChartUPlot` component, otherwise uPlot instance may get out of sync with the rendered component. Instead, use a `useMemo` hook to memoize the options and data.
158
+
155
159
## Contributing
156
160
157
161
If you would like to contribute, please open an issue or a pull request. Contributions are welcome!
0 commit comments