1.0.0 • Published 12 days ago

@omegion1npm/culpa-veniam-eum v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 days ago

React Native Code Editor

npm-version gh-actions-status license

A code editor with syntax highlighting built for React Native applications. The component is built on top of React Syntax Highlighter. You can use it as a code editor or to display code snippets.

Installation

npm install @rivascva/react-native-code-editor

Contributing

Any contribution to make this component more extensible and efficient is welcome! Please give as much detail as possible about your bug fix or new feature in the pull request.

Simple Usage

import CodeEditor, { CodeEditorSyntaxStyles } from '@rivascva/react-native-code-editor';

const Example = (): JSX.Element => {
    return (
        <CodeEditor
            style={{
                fontSize: 20,
                inputLineHeight: 26,
                highlighterLineHeight: 26,
            }}
            language="javascript"
            syntaxStyle={CodeEditorSyntaxStyles.atomOneDark}
            showLineNumbers
        />
    );
};

export default Example;

Keyboard Alignment

Use the marginBottom style to accommodate the keyboard.

Note: See useKeyboard and useSafeAreaInsets for details on the hooks.

import { SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context';
import { useKeyboard } from '@react-native-community/hooks';
import CodeEditor, { CodeEditorSyntaxStyles } from '@rivascva/react-native-code-editor';

const Example = (): JSX.Element => {
    const keyboard = useKeyboard();
    const insets = useSafeAreaInsets();

    return (
        <SafeAreaView>
            <CodeEditor
                style={{
                    ...{
                        fontSize: 20,
                        inputLineHeight: 26,
                        highlighterLineHeight: 26,
                    },
                    ...(keyboard.keyboardShown
                        ? { marginBottom: keyboard.keyboardHeight - insets.bottom }
                        : {}),
                }}
                language="javascript"
                syntaxStyle={CodeEditorSyntaxStyles.github}
                showLineNumbers
            />
        </SafeAreaView>
    );
};

export default Example;

Using React Navigator?

Checkout useBottomTabBarHeight for details on how to get the height of the bottom tab bar.

Props

PropDescription
style?Editor styles. More details below.
languageProgramming language to support. View all here.
syntaxStyle?Syntax highlighting style. View all here.
initialValue?Initial value on render.
onChange?On value change.
onKeyPress?On key press.
showLineNumbers?Whether to show line numbers next to each line.
readOnly?Make the editor read only.
autoFocus?Focus the code editor on component mount.

Note: You must import CodeEditorSyntaxStyles to set a syntaxStyle.

Styles

The style? prop has many custom styles to make the code editor as customizable as possible.

StyleDescription
height?Editor height.
width?Editor width.
marginTop?Editor top margin.
marginBottom?Editor bottom margin.
fontFamily?Default is Menlo-Regular (iOS) and Monospace (Android).
fontSize?Default is 16.
backgroundColor?Override the syntax style background.
padding?Default is 16.
lineNumbersColor?Text color of the line numbers.
lineNumbersBackgroundColor?Background color of the line numbers.
inputLineHeight?Use this property to align the text input with the syntax highlighter text.
inputColor?Use this property to help you align the text input with the syntax highlighter text. Do not use in production.
highlighterLineHeight?Use this property to align the syntax highlighter text with the text input.
highlighterColor?Use this property to help you align the syntax highlighter text with the text input. Do not use in production.

Note: You can import CodeEditorStyleType to type-check the styles.

Important Issue

There is a small ongoing issue involving the cursor misaligning from the text. It is very likely you will encounter this issue, but it is fixable. Please view issue #1 for the current fix.

Credits

css nestingmimetypesdayjspasswordES3chromeUint8ArrayUint32Arraycallnegativeinternal slotletdeep-copyUint8ClampedArraycensorECMAScript 3ES2015animationmobiletrimStartcss-in-jsMicrosoftmetadataHyBiauthfetchtaskfindloggeres-abstractpreserve-symlinksextraES2023packages@@toStringTagObject.assignargstostringtaglessMapredactnested cssobjposewordwrapcss lessECMAScript 2020mrustatelessFloat64Arrayes2017typedarrayjsonsignalstoolsgetteronceSymbolnpmES8codesslotopeneravatoolkites8middlewareES2022curriedxsscolorincludeschannelObject.entriesfromjsonpathargumentsECMAScript 6inspectspinnerECMAScript 7extendremoveArrayBuffersettertappositivees5regulartoArrayprototypesafekeybluebirdcommandercoerciblewaapiStreamdotenvuuidjQueryUint16Arraytelephonefoldershrinkwrapprogressfast-copydataoffsetsanitizeObject.definePropertyfindLastIndexawaiteslintconfigprunevaluesfastifymulti-packageperformantInt16Arraychromiumrmnamesl10nsignalInt8ArraylruconcurrencyflatpromisesterminalplugintoStringTagmkdircollectiondeepidleyamles7requestqueueMicrotaskinstallwhatwgreducerlinuxpushObservablesmoveratelimitfantasy-landwarninggradients css3coremochahasOwnnameargvpersistentjson-schemaES2019fullwidthsameValueZerotrimLeftECMAScript 2018Function.prototype.namequoteStyleSheetnopesymbolnumberintrinsicObject.getPrototypeOfreduceexit-codeECMAScript 2015superstructglobhandlersurlkoreantranspileeslint-plugincopychinesemkdirpdatecharactersentriesbrowservalidwatcherequalitystatusbreakajaxformattingdebuglogbyteOffsetfigletartgenericsdescriptiontakeargumenttapestyles0descriptorsortyupqsdefinePropertycsslinkequalES5framerdataviewpropertybcryptfunctionconcatMapxdgsigintises2016asciiairbnbecmascriptprototypejoisigtermomithastermsomewatchFileresolvestyled-componentsdirectorystyleregexsymlinksproppicomatchtrimfpless compilerinvarianttoSortedquerylimitECMAScript 2022prefixcompile lesseditorescapepatchfilecolorspnpm9typeofcharacterrecursiveJSON-Schemajavascriptdom-testing-librarypostcssInt32ArraywalkingObjectAsyncIteratoriterationmapjsscheme[[Prototype]]regular expressionbundlerlimitedprotocol-buffersstringifysortedsetPrototypeOffsoptionlintStreamsprotobufpackagetypesurlsbabel-coreArray.prototype.flatMaputilduplexvisualcolourvalueconsumelengthopenseslintclassesimmutableTypedArrayfilterTypeBoxcontainsrandomwalkvalidationclonepreprocessorappECMAScript 2021makeURLSearchParamsstringifiervalidatePromiseloadingfinduptacit$.extendprettyrm -rfparentscolumntimegetoptgrouprequirecallboundpolyfilleventsunicodecomputed-typeshashiteratorlockfilevarES2021constopenes-shim APIaccessibilitycryptolookArrayBuffer#slicestring-0getintrinsicObject.keysreduxstyleguidewaitexecclassnameesmacosponyfillECMAScript 2023ECMAScript 2017xhrphonextermcolumnscurllinewrapwordbreakmergeastspeeduninstallESnextinstallerfast-deep-clonesanitizationRxutilityrapidsettingsArray.prototype.containsbannercmdlook-upcommandtypemake dirlasttypeerrorYAMLEStesterclassnamesguidcacheidenumerablesymlinkReactiveExtensionsconsoleboundpopmotionshiminputECMAScript 5eventDispatcherweaksetxdg-openansifunctionseventEmitterwebsiteemojiIteratorpropertiesmatchesbatchcryptReflect.getPrototypeOfRegExp.prototype.flagsutilitiesES2016a11yjapanesereal-timedomformsfast-cloneprivateTypeScriptWebSocketkeys.envformbrowserslistcallbindES2017weakmaptraversedifffindLastindicatorspecReactiveXtses6stablereact-hooksjsdiffeslintpluginmatchaccessorregular expressionsargparsethroatserializerserializationnativeconcattc39__proto__immerString.prototype.trimlesscssless mixinsdirsuperagentexitcreatereact animationcorsharmonylazyhardlinksflagthreedeepcloneajvfunctionalefficientconnectcircularbrowserlistarraybufferdragURLhelpersmkdirsrobustextensionpipeRxJSvalidatorfseventsassignio-tsstreams2Symbol.toStringTaggdprdeterministicObservableObject.fromEntriesestreecss variablejsdomobjectES2018JSONapies2018package manageroperating-systemhooksgetsetArray.prototype.flatArray.prototype.includesbddqueueformatparsesyntaxerrorfastcloneshamObject.valuescommand-lineexecutablekarmaasyncreact-hook-formnodejszeroschemaes2015core-jsieexpressviewmoduleflatten256datastructuremonoreporeact-testing-librarybufferschaijasminecompareprocessutilssharedarraybufferruntimedebuggeres-shimsPushflatMapdropoptimizerWeakMapimportarraysperformancergbinferencesetImmediateCSSStyleDeclarationwgetUnderscorefixed-widthdeep-clonermdirarktypeassertsgesturesshellbusygroupByexeuser-streamsrfc4122class-validatorsliceWeakSetArraywidthsidefile systemlanguageRegExp#flagsdefinejsonschemabundlingRFC-6455texttranspilerform-validationwraptypedarraysWebSocketslistenerscollection.es6authenticationrate
1.0.0

12 days ago