Skip to content

Commit

Permalink
Merge branch 'main' into multiple-blockquotes-ios
Browse files Browse the repository at this point in the history
  • Loading branch information
robertKozik committed Jan 10, 2024
2 parents b1cad7a + 11a21dc commit 5916495
Show file tree
Hide file tree
Showing 89 changed files with 484 additions and 515 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/node_modules/*
parser/out.js
parser/react-native-live-markdown-parser.js
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
],
settings: {
'import/resolver': {
alias: [['react-native-markdown-text-input', './src/index.tsx']],
alias: [['@expensify/react-native-live-markdown', './src/index.tsx']],
},
},
root: true,
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ android/keystores/debug.keystore
# generated by bob
lib/

# react-native-markdown-text-input
android/src/main/assets/out.js
# react-native-live-markdown
android/src/main/assets/react-native-live-markdown-parser.js
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ The [example app](/example/) demonstrates usage of the library. You need to run

It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app.

If you want to use Android Studio or XCode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/MarkdownTextInputExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-markdown-text-input`.
If you want to use Android Studio or XCode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/LiveMarkdownExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-live-markdown`.

To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `react-native-markdown-text-input` under `Android`.
To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `react-native-live-markdown` under `Android`.

You can use various commands from the root directory to work with the project.

Expand Down Expand Up @@ -71,7 +71,7 @@ yarn clean
To confirm that the app is running with the new architecture, you can check the Metro logs for a message like this:

```sh
Running "MarkdownTextInputExample" with {"fabric":true,"initialProps":{"concurrentRoot":true},"rootTag":1}
Running "LiveMarkdownExample" with {"fabric":true,"initialProps":{"concurrentRoot":true},"rootTag":1}
```

Note the `"fabric":true` and `"concurrentRoot":true` properties.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Tomasz Zawadzki
Copyright (c) 2024 Expensify, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# react-native-markdown-text-input
# @expensify/react-native-live-markdown

Lorem ipsum sit dolor amet.

## Installation

```sh
npm install react-native-markdown-text-input
npm install @expensify/react-native-live-markdown
```

## Usage

```js
import { MarkdownTextInputView } from "react-native-markdown-text-input";
import { MarkdownTextInput } from '@expensify/react-native-live-markdown';

// ...

<MarkdownTextInputView color="tomato" />
<MarkdownTextInput />;
```

## Contributing
Expand Down
3 changes: 1 addition & 2 deletions WebExample/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const createExpoWebpackConfigAsync = require('@expo/webpack-config');
const pak = require('../package.json');

module.exports = async function (env, argv) {
const config = await createExpoWebpackConfigAsync(
{
...env,
babel: {
dangerouslyAddModulePathsToTranspile: [pak.name],
dangerouslyAddModulePathsToTranspile: ['react-native-live-markdown'],
},
},
argv
Expand Down
12 changes: 6 additions & 6 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ if (isNewArchitectureEnabled()) {
}

def getExtOrDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["MarkdownTextInput_" + name]
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["LiveMarkdown_" + name]
}

def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["MarkdownTextInput_" + name]).toInteger()
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["LiveMarkdown_" + name]).toInteger()
}

def supportsNamespace() {
Expand All @@ -38,7 +38,7 @@ def supportsNamespace() {

android {
if (supportsNamespace()) {
namespace "com.markdowntextinput"
namespace "com.expensify.livemarkdown"

sourceSets {
main {
Expand Down Expand Up @@ -128,13 +128,13 @@ dependencies {
if (isNewArchitectureEnabled()) {
react {
jsRootDir = file("../src/")
libraryName = "MarkdownTextInputView"
codegenJavaPackageName = "com.markdowntextinput"
libraryName = "LiveMarkdown"
codegenJavaPackageName = "com.expensify.livemarkdown"
}
}

task copyJS(type: Copy) {
from '../parser/out.js'
from '../parser/react-native-live-markdown-parser.js'
into 'src/main/assets'
}

Expand Down
10 changes: 5 additions & 5 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MarkdownTextInput_kotlinVersion=1.7.0
MarkdownTextInput_minSdkVersion=21
MarkdownTextInput_targetSdkVersion=31
MarkdownTextInput_compileSdkVersion=31
MarkdownTextInput_ndkversion=21.4.7075529
LiveMarkdown_kotlinVersion=1.7.0
LiveMarkdown_minSdkVersion=21
LiveMarkdown_targetSdkVersion=31
LiveMarkdown_compileSdkVersion=31
LiveMarkdown_ndkversion=21.4.7075529
2 changes: 1 addition & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.markdowntextinput">
package="com.expensify.livemarkdown">
</manifest>
6 changes: 3 additions & 3 deletions android/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
project("markdowntextinput")
project("livemarkdown")

cmake_minimum_required(VERSION 3.13)

set(CMAKE_VERBOSE_MAKEFILE on)

add_compile_options(-fvisibility=hidden -fexceptions -frtti)

file(GLOB markdowntextinput_SRC CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
file(GLOB livemarkdown_SRC CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)

add_library(${CMAKE_PROJECT_NAME} SHARED ${markdowntextinput_SRC})
add_library(${CMAKE_PROJECT_NAME} SHARED ${livemarkdown_SRC})

target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

Expand Down
18 changes: 13 additions & 5 deletions android/src/main/cpp/MarkdownUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

using namespace facebook;

namespace markdowntextinput {
namespace expensify {
namespace livemarkdown {
std::shared_ptr<jsi::Runtime> MarkdownUtils::runtime_;

void MarkdownUtils::nativeInitializeRuntime(
Expand All @@ -21,9 +22,15 @@ namespace markdowntextinput {
jni::alias_ref<jhybridobject> jThis,
jni::alias_ref<jni::JString> input) {
jsi::Runtime &rt = *runtime_;
auto func = rt.global().getPropertyAsFunction(rt, "parseMarkdownToTextAndRanges");
auto output = func.call(rt, input->toStdString());
auto json = rt.global().getPropertyAsObject(rt, "JSON").getPropertyAsFunction(rt, "stringify").call(rt, output).asString(rt).utf8(rt);
auto func = rt.global().getPropertyAsFunction(rt, "parseExpensiMarkToRanges");
auto arg = input->toStdString();
jsi::Value result;
try {
result = func.call(rt, arg);
} catch (jsi::JSError e) {
result = jsi::Array(rt, 0);
}
auto json = rt.global().getPropertyAsObject(rt, "JSON").getPropertyAsFunction(rt, "stringify").call(rt, result).asString(rt).utf8(rt);
return jni::make_jstring(json);
}

Expand All @@ -33,4 +40,5 @@ namespace markdowntextinput {
makeNativeMethod("nativeParseMarkdown", MarkdownUtils::nativeParseMarkdown)});
}

} // namespace markdowntextinput
} // namespace livemarkdown
} // namespace expensify
8 changes: 5 additions & 3 deletions android/src/main/cpp/MarkdownUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@

using namespace facebook;

namespace markdowntextinput {
namespace expensify {
namespace livemarkdown {

class MarkdownUtils : public jni::HybridClass<MarkdownUtils>,
public jsi::HostObject {
public:
static constexpr auto kJavaDescriptor =
"Lcom/markdowntextinput/MarkdownUtils;";
"Lcom/expensify/livemarkdown/MarkdownUtils;";

static void nativeInitializeRuntime(
jni::alias_ref<jhybridobject> jThis,
Expand All @@ -36,4 +37,5 @@ namespace markdowntextinput {
friend HybridBase;
};

} // namespace markdowntextinput
} // namespace livemarkdown
} // namespace expensify
2 changes: 1 addition & 1 deletion android/src/main/cpp/OnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return facebook::jni::initialize(
vm, [] { markdowntextinput::MarkdownUtils::registerNatives(); });
vm, [] { expensify::livemarkdown::MarkdownUtils::registerNatives(); });
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

package com.markdowntextinput;
package com.expensify.livemarkdown;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
Expand All @@ -10,11 +9,11 @@
import java.util.Collections;
import java.util.List;

public class MarkdownTextInputViewPackage implements ReactPackage {
public class LiveMarkdownPackage implements ReactPackage {
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
List<ViewManager> viewManagers = new ArrayList<>();
viewManagers.add(new MarkdownTextInputViewManager());
viewManagers.add(new MarkdownTextInputDecoratorViewManager());
return viewManagers;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.markdowntextinput;
package com.expensify.livemarkdown;

import android.content.Context;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.markdowntextinput;
package com.expensify.livemarkdown;

import androidx.annotation.Nullable;

Expand All @@ -12,17 +12,17 @@

import com.facebook.react.views.textinput.ReactEditText;

public class MarkdownTextInputView extends View {
public class MarkdownTextInputDecoratorView extends View {

public MarkdownTextInputView(Context context) {
public MarkdownTextInputDecoratorView(Context context) {
super(context);
}

public MarkdownTextInputView(Context context, @Nullable AttributeSet attrs) {
public MarkdownTextInputDecoratorView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}

public MarkdownTextInputView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
public MarkdownTextInputDecoratorView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.expensify.livemarkdown;

import androidx.annotation.NonNull;

import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.annotations.ReactProp;

@ReactModule(name = MarkdownTextInputDecoratorViewManager.NAME)
public class MarkdownTextInputDecoratorViewManager extends MarkdownTextInputDecoratorViewManagerSpec<MarkdownTextInputDecoratorView> {

public static final String NAME = "MarkdownTextInputDecoratorView";

@Override
public String getName() {
return NAME;
}

@Override
public MarkdownTextInputDecoratorView createViewInstance(ThemedReactContext context) {
return new MarkdownTextInputDecoratorView(context);
}

@Override
@ReactProp(name = "markdownStyle")
public void setMarkdownStyle(@NonNull MarkdownTextInputDecoratorView view, @NonNull ReadableMap value) {
MarkdownStyle markdownStyle = new MarkdownStyle(value, view.getContext());
view.setMarkdownStyle(markdownStyle);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.markdowntextinput;
package com.expensify.livemarkdown;

import android.text.Editable;
import android.text.SpannableStringBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.markdowntextinput;
package com.expensify.livemarkdown;

import static com.facebook.infer.annotation.ThreadConfined.UI;

Expand Down Expand Up @@ -33,7 +33,7 @@

public class MarkdownUtils {
static {
SoLoader.loadLibrary("markdowntextinput");
SoLoader.loadLibrary("livemarkdown");
}

private static boolean IS_RUNTIME_INITIALIZED = false;
Expand All @@ -45,7 +45,7 @@ public static void maybeInitializeRuntime(AssetManager assetManager) {
return;
}
try {
InputStream inputStream = assetManager.open("out.js");
InputStream inputStream = assetManager.open("react-native-live-markdown-parser.js");
byte[] buffer = new byte[inputStream.available()];
inputStream.read(buffer);
inputStream.close();
Expand Down Expand Up @@ -155,14 +155,7 @@ public void applyMarkdownFormatting(SpannableStringBuilder ssb) {
String input = ssb.toString();
String output = parseMarkdown(input);
try {
JSONArray array = new JSONArray(output);
String text = array.getString(0);

if (!ssb.toString().equals(text)) {
return;
}

JSONArray ranges = array.getJSONArray(1);
JSONArray ranges = new JSONArray(output);
for (int i = 0; i < ranges.length(); i++) {
JSONArray range = ranges.getJSONArray(i);
String type = range.getString(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.markdowntextinput;
package com.expensify.livemarkdown;

import android.graphics.Canvas;
import android.graphics.Paint;
Expand Down
Loading

0 comments on commit 5916495

Please sign in to comment.