Skip to content

Commit

Permalink
Merge branch 'main' into @wolewicki/rn-075-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekzaw committed Sep 2, 2024
2 parents 466ab36 + 73488ad commit 8797550
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 35 deletions.
8 changes: 8 additions & 0 deletions RNLiveMarkdown.podspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require "json"

react_native_node_modules_dir = ENV['REACT_NATIVE_NODE_MODULES_DIR'] || File.join(File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`), '..')
react_native_json = JSON.parse(File.read(File.join(react_native_node_modules_dir, 'react-native/package.json')))
react_native_minor_version = react_native_json['version'].split('.')[1].to_i

package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

Expand All @@ -20,6 +24,10 @@ Pod::Spec.new do |s|

s.dependency "hermes-engine"

s.xcconfig = {
"OTHER_CFLAGS" => "$(inherited) -DREACT_NATIVE_MINOR_VERSION=#{react_native_minor_version}"
}

install_modules_dependencies(s)

if ENV['USE_FRAMEWORKS'] && ENV['RCT_NEW_ARCH_ENABLED']
Expand Down
49 changes: 46 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["LiveMarkdown_" + name]).toInteger()
}

def safeAppExtGet(prop, fallback) {
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
appProject?.ext?.has(prop) ? appProject.ext.get(prop) : fallback
}

def supportsNamespace() {
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
def major = parsed[0].toInteger()
Expand All @@ -41,6 +46,40 @@ def supportsNamespace() {
return (major == 7 && minor >= 3) || major >= 8
}

def resolveReactNativeDirectory() {
def reactNativeLocation = safeAppExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
if (reactNativeLocation != null) {
return file(reactNativeLocation)
}

// monorepo workaround
// react-native can be hoisted or in project's own node_modules
def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
if (reactNativeFromProjectNodeModules.exists()) {
return reactNativeFromProjectNodeModules
}

def reactNativeFromLiveMarkdownMonorepo = file("${projectDir}/../../../node_modules/react-native")
if (reactNativeFromLiveMarkdownMonorepo.exists()) {
return reactNativeFromLiveMarkdownMonorepo
}

def reactNativeFromNodeModulesWithLiveMarkdown = file("${projectDir}/../../react-native")
if (reactNativeFromNodeModulesWithLiveMarkdown.exists()) {
return reactNativeFromNodeModulesWithLiveMarkdown
}

throw new GradleException("[react-native-live-markdown] Unable to resolve react-native location in node_modules. Your app should define `REACT_NATIVE_NODE_MODULES_DIR` extension property in `app/build.gradle` with a path to react-native in node_modules.")
}

def getReactNativeMinorVersion() {
def reactNativeRootDir = resolveReactNativeDirectory()
def reactNativeProperties = new Properties()
file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactNativeProperties.load(it) }
def reactNativeVersion = reactNativeProperties.getProperty("VERSION_NAME")
return reactNativeVersion.split("\\.")[1].toInteger()
}

android {
if (supportsNamespace()) {
namespace "com.expensify.livemarkdown"
Expand All @@ -57,13 +96,17 @@ android {
defaultConfig {
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")

buildConfigField "int", "REACT_NATIVE_MINOR_VERSION", getReactNativeMinorVersion().toString()
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

consumerProguardFiles "proguard-rules.pro"

externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared", "-DANDROID_TOOLCHAIN=clang"
arguments "-DANDROID_STL=c++_shared",
"-DANDROID_TOOLCHAIN=clang",
"-DREACT_NATIVE_MINOR_VERSION=${getReactNativeMinorVersion()}"
abiFilters (*reactNativeArchitectures())
}
}
Expand Down
2 changes: 2 additions & 0 deletions android/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ set(CMAKE_VERBOSE_MAKEFILE on)

add_compile_options(-fvisibility=hidden -fexceptions -frtti)

string(APPEND CMAKE_CXX_FLAGS " -DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}")

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

add_library(${CMAKE_PROJECT_NAME} SHARED ${livemarkdown_SRC})
Expand Down
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ PODS:
- React-logger (= 0.75.2)
- React-perflogger (= 0.75.2)
- React-utils (= 0.75.2)
- RNLiveMarkdown (0.1.125):
- RNLiveMarkdown (0.1.128):
- DoubleConversion
- glog
- hermes-engine
Expand All @@ -1517,9 +1517,9 @@ PODS:
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNLiveMarkdown/common (= 0.1.125)
- RNLiveMarkdown/common (= 0.1.128)
- Yoga
- RNLiveMarkdown/common (0.1.125):
- RNLiveMarkdown/common (0.1.128):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1805,7 +1805,7 @@ SPEC CHECKSUMS:
React-utils: 81a715d9c0a2a49047e77a86f3a2247408540deb
ReactCodegen: 60973d382704c793c605b9be0fc7f31cb279442f
ReactCommon: 6ef348087d250257c44c0204461c03f036650e9b
RNLiveMarkdown: 47f37b0efc07d21e855c5475dbe3aabbb5f5a5b3
RNLiveMarkdown: 44cc9af8742cfd5355733d29fa54e64e4edf0f0d
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
Yoga: 2a45d7e59592db061217551fd3bbe2dd993817ae

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@expensify/react-native-live-markdown",
"version": "0.1.125",
"version": "0.1.128",
"description": "Drop-in replacement for React Native's TextInput component with Markdown formatting.",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
4 changes: 1 addition & 3 deletions src/__tests__/webParser.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {expect} from '@jest/globals';
import {parseRangesToHTMLNodes} from '../web/utils/parserUtils';
import type {MarkdownRange} from '../web/utils/parserUtils';

require('../../parser/react-native-live-markdown-parser.js');

Expand All @@ -16,8 +15,7 @@ const toBeParsedAsHTML = function (actual: string, expectedHTML: string) {
throw new Error('Actual value must be a string');
}
let expected = expectedHTML;
const ranges = global.parseExpensiMarkToRanges(actual);
const markdownRanges = ranges as MarkdownRange[];
const markdownRanges = global.parseExpensiMarkToRanges(actual);

const actualDOM = parseRangesToHTMLNodes(actual, markdownRanges, {}, true).dom;
const actualHTML = actualDOM.innerHTML;
Expand Down
10 changes: 10 additions & 0 deletions src/commonTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'mention-here' | 'mention-user' | 'mention-report' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax';

interface MarkdownRange {
type: MarkdownType;
start: number;
length: number;
depth?: number;
}

export type {MarkdownType, MarkdownRange};
15 changes: 2 additions & 13 deletions src/web/utils/parserUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@ import type {NodeType, TreeNode} from './treeUtils';
import type {PartialMarkdownStyle} from '../../styleUtils';
import {getCurrentCursorPosition, moveCursorToEnd, setCursorPosition} from './cursorUtils';
import {addStyleToBlock} from './blockUtils';

type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax' | 'mention-here' | 'mention-user' | 'mention-report';

type MarkdownRange = {
type: MarkdownType;
start: number;
length: number;
depth?: number;
};
import type {MarkdownRange} from '../../commonTypes';

type Paragraph = {
text: string;
Expand Down Expand Up @@ -271,8 +263,7 @@ function updateInputStructure(
const selection = getCurrentCursorPosition(target);
cursorPosition = selection ? selection.start : null;
}
const ranges = global.parseExpensiMarkToRanges(text);
const markdownRanges: MarkdownRange[] = ranges as MarkdownRange[];
const markdownRanges = global.parseExpensiMarkToRanges(text);
if (!text || targetElement.innerHTML === '<br>' || (targetElement && targetElement.innerHTML === '\n')) {
targetElement.innerHTML = '';
targetElement.innerText = '';
Expand All @@ -298,5 +289,3 @@ function updateInputStructure(
}

export {updateInputStructure, parseRangesToHTMLNodes};

export type {MarkdownRange, MarkdownType};
2 changes: 1 addition & 1 deletion src/web/utils/treeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {HTMLMarkdownElement} from '../../MarkdownTextInput.web';
import type {MarkdownRange, MarkdownType} from './parserUtils';
import type {MarkdownRange, MarkdownType} from '../../commonTypes';

type NodeType = MarkdownType | 'line' | 'text' | 'br' | 'root';

Expand Down
13 changes: 3 additions & 10 deletions types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
export {};

type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'mention-here' | 'mention-user' | 'mention-report' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax';
import type {MarkdownRange} from '../src/commonTypes';

type MarkdownRange = {
type: MarkdownType;
start: number;
length: number;
depth?: number;
};
export {};

declare global {
// eslint-disable-next-line no-var
var parseExpensiMarkToRanges: (markdown: string) => MarkdownMarkdownRange[];
var parseExpensiMarkToRanges: (markdown: string) => MarkdownRange[];
}

0 comments on commit 8797550

Please sign in to comment.