diff --git a/morse/App.js b/morse/App.js new file mode 100644 index 0000000..d4be97b --- /dev/null +++ b/morse/App.js @@ -0,0 +1,49 @@ +import * as React from 'react'; +import { Component, useState } from 'react'; +import { Text, Button, Alert, TextInput, View, StyleSheet } from 'react-native'; +import Constants from 'expo-constants'; + +// You can import from local files +import AssetExample from './components/AssetExample'; + +// or any pure javascript modules available in npm +import { Card } from 'react-native-paper'; + +var MORSE_CODE = {".-": "a", "-...":"b", "-.-.": "c", "-..": "d", ".":"e", "..-.":"f", "--.":"g", "....":"h", "..":"i", ".---":"j", "-.-":"k", ".-..":"l", "--":"m", "-.":"n", "---":"o", ".--.":"p", "--.-":"q", ".-.":"r", "...":"s", "-":"t", "..-":"u", "...-":"v", ".--":"w", "-..-":"x", "-.--":"y", "--..":"z", ".----":"1", "..---":"2", "...--":"3", "....-":"4", ".....":"5", "-....":"6", "--...":"7", "---..":"8", "----.":"9", "-----":"0", "|":" "}; + +var decodeMorse = function(morseCode){ + var words = (morseCode).split(' '); + var letters = words.map((w) => w.split('|')); + var decoded = []; + + for(var i = 0; i < letters.length; i++){ + decoded[i] = []; + for(var x = 0; x < letters[i].length; x++){ + if(MORSE_CODE[letters[i][x]]){ + decoded[i].push( MORSE_CODE[letters[i][x]] ); + } + } + } + + return decoded.map(arr => arr.join('')).join(' '); +} + +export default function App() { + const [text, setText] = useState(''); + + return ( + + setText(text)} + defaultValue={text} + /> + + {decodeMorse(text)} + + + ); +} + + diff --git a/morse/README.md b/morse/README.md new file mode 100644 index 0000000..5d05d0d --- /dev/null +++ b/morse/README.md @@ -0,0 +1,11 @@ +# Sample Snack app + +Open the `App.js` file to start writing some code. You can preview the changes directly on your phone or tablet by clicking the **Run** button or use the simulator by clicking **Tap to Play**. When you're done, click **Save** and share the link! + +When you're ready to see everything that Expo provides (or if you want to use your own editor) you can **Export** your project and use it with [expo-cli](https://docs.expo.io/versions/latest/introduction/installation.html). + +All projects created in Snack are publicly available, so you can easily share the link to this project via link, or embed it on a web page with the **Embed** button. + +If you're having problems, you can tweet to us [@expo](https://twitter.com/expo) or ask in our [forums](https://forums.expo.io). + +Snack is Open Source. You can find the code on the [GitHub repo](https://github.com/expo/snack-web). diff --git a/morse/app.json b/morse/app.json new file mode 100644 index 0000000..83fa0c6 --- /dev/null +++ b/morse/app.json @@ -0,0 +1,28 @@ +{ + "expo": { + "name": "morse", + "description": "No description", + "slug": "snack-1b8a79e5-e20c-4460-92bf-0bb1222b7842", + "privacy": "unlisted", + "sdkVersion": "37.0.0", + "version": "1.0.0", + "orientation": "portrait", + "primaryColor": "#cccccc", + "icon": "https://d1wp6m56sqw74a.cloudfront.net/~assets/c9aa1be8a6a6fe81e20c3ac4106a2ebc", + "loading": { + "icon": "https://d1wp6m56sqw74a.cloudfront.net/~assets/c9aa1be8a6a6fe81e20c3ac4106a2ebc", + "hideExponentText": false + }, + "packagerOpts": { + "assetExts": [ + "ttf", + "mp4", + "otf", + "xml" + ] + }, + "ios": { + "supportsTablet": true + } + } +} \ No newline at end of file diff --git a/morse/assets/icons/app-icon.png b/morse/assets/icons/app-icon.png new file mode 100644 index 0000000..3f5bbc0 Binary files /dev/null and b/morse/assets/icons/app-icon.png differ diff --git a/morse/assets/icons/loading-icon.png b/morse/assets/icons/loading-icon.png new file mode 100644 index 0000000..3f5bbc0 Binary files /dev/null and b/morse/assets/icons/loading-icon.png differ diff --git a/morse/assets/snack-icon.png b/morse/assets/snack-icon.png new file mode 100644 index 0000000..cce03a3 Binary files /dev/null and b/morse/assets/snack-icon.png differ diff --git a/morse/babel.config.js b/morse/babel.config.js new file mode 100644 index 0000000..3c99cc4 --- /dev/null +++ b/morse/babel.config.js @@ -0,0 +1,6 @@ +module.exports = function(api) { +api.cache(true) +return { + presets: ['babel-preset-expo'], +} +}; \ No newline at end of file diff --git a/morse/components/AssetExample.js b/morse/components/AssetExample.js new file mode 100644 index 0000000..8932e0c --- /dev/null +++ b/morse/components/AssetExample.js @@ -0,0 +1,32 @@ +import * as React from 'react'; +import { Text, View, StyleSheet, Image } from 'react-native'; + +export default function AssetExample() { + return ( + + + Local files and assets can be imported by dragging and dropping them into the editor + + + + ); +} + +const styles = StyleSheet.create({ + container: { + alignItems: 'center', + justifyContent: 'center', + padding: 24, + }, + paragraph: { + margin: 24, + marginTop: 0, + fontSize: 14, + fontWeight: 'bold', + textAlign: 'center', + }, + logo: { + height: 128, + width: 128, + } +}); diff --git a/morse/package.json b/morse/package.json new file mode 100644 index 0000000..8f7ff47 --- /dev/null +++ b/morse/package.json @@ -0,0 +1,17 @@ +{ + "name": "morse", + "version": "0.0.0", + "description": "No description", + "author": null, + "private": true, + "main": "node_modules/expo/AppEntry.js", + "devDependencies": { + "babel-preset-expo": "^7.0.0" + }, + "dependencies": { + "expo": "^37.0.0", + "react": "16.9.0", + "react-native": "https://github.com/expo/react-native/archive/sdk-37.0.0.tar.gz", + "react-native-paper": "3.6.0" + } +} \ No newline at end of file