0
import abcjs from 'abcjs';

export default class MusicScore extends Component {
    constructor(props) {
        super(props);
        this.state={
            data: this.props.navigation.getParam('abctune'),
        }
    }
    render(){
        data = this.state.data;
        renderScore = () => {
            abcjs.renderAbc('notation', data);
        }
        return(
            <WebView 
                source={
                    {html: `
                        <!DOCTYPE html>
                        <html lang="en">
                        <head>
                            <meta charset="UTF-8">
                            <meta name="viewport" content="width=device-width, initial-scale=1.0">
                            <title>Document</title>
                        </head>
                        <body>
                            <div id="notation"></div>
                        </body>
                        </html>
                    `}
                }
                domStorageEnabled
                javaScriptEnabled
                injectJavaScript={renderScore}
            />
        );
    }
}

The code above produces the following

enter image description here

OUTPUT

dev enviornment:

OS: Windows 10

node: v12.10.0

Android Studio: 3.5.2

installed via package manager:

npm install --save abcjs

Community
  • 1
  • 1
Philip Butler
  • 479
  • 1
  • 5
  • 13

1 Answers1

0

Unfortunately, you need a DOM set up. I haven't used react-native, so I'm not sure if this will work:

What works for me when using a SSR package (like Nuxt) is to change the import to later in the process. So:

mounted() {
  const abcjs = require('abcjs');
}

Is there something analogous in react-native?

Paulie
  • 1,940
  • 3
  • 20
  • 34
  • Just wanted to add that they also say this in their FAQ: [Can I use ABCJS in React Native/other mobile development frameworks?](https://paulrosen.github.io/abcjs/overview/faq.html#can-i-use-abcjs-in-react-native-other-mobile-development-frameworks) – Marius Jan 16 '21 at 13:44