Skip to content

Commit

Permalink
Merge branch 'main' into @maksg/performance-fixes-ios
Browse files Browse the repository at this point in the history
  • Loading branch information
maksg committed Oct 14, 2024
2 parents 7004739 + b97a0a6 commit 39b7432
Show file tree
Hide file tree
Showing 81 changed files with 1,259 additions and 327 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ parser/react-native-live-markdown-parser.js

# any js file inside android and ios folders
**/android/**/*.js
**/ios/**/*.js
**/apple/**/*.js

# Output of the build process & scripts
lib/**/*
Expand Down
Binary file modified .github/OSBotify-private-key.asc.gpg
Binary file not shown.
4 changes: 2 additions & 2 deletions .github/workflows/build-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
paths:
- .github/workflows/build-ios.yml
- RNLiveMarkdown.podspec
- ios/**
- apple/**
- cpp/**
- example/package.json
- example/ios/**
Expand All @@ -17,7 +17,7 @@ on:
paths:
- .github/workflows/build-ios.yml
- RNLiveMarkdown.podspec
- ios/**
- apple/**
- cpp/**
- example/package.json
- example/ios/**
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

- name: Set up git for OSBotify
run: |
git config --global user.signingkey 367811D53E34168C
git config --global user.signingkey AEE1036472A782AB
git config --global commit.gpgsign true
git config --global user.name OSBotify
git config --global user.email [email protected]
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ lib/
# react-native-live-markdown
android/src/main/assets/react-native-live-markdown-parser.js
.build_complete

# GitHub GPG Keys
.github/OSBotify-private-key.asc
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,16 @@ When you're sending a pull request:
- Review the documentation to make sure it looks good.
- Follow the pull request template when opening a pull request.
- For pull requests that change the API or implementation, discuss with maintainers first by opening an issue.

### Testing with Expensify/App (or other projects)
It's possible to locally develop this repo such with live-reload in another React Native project. These instructions are for Expensify/App, but they can be adapted to other repos as well.

1. Clone this repo
2. Run `yarn install`
3. Run `yarn build:watch`
4. In Expensify/App, run `npm install`.
- _Note:_ There is a patch for the `link` dev dependency in this repo. If you want these steps to work reliably, you'll likely need to copy that patch over.
5. In Expensify/App, run `npx link publish --watch ~/react-native-live-markdown --litmus .build_complete`
6. In E/App, run the app with `npm run web`/`npm run ios`/etc...

The end result should be that you can make a change directly in this repo, and your changes will live-reload in E/App.
10 changes: 6 additions & 4 deletions RNLiveMarkdown.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Pod::Spec.new do |s|
s.platforms = { :ios => "11.0", :visionos => "1.0" }
s.source = { :git => "https://github.com/expensify/react-native-live-markdown.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,mm}"
s.source_files = "apple/**/*.{h,m,mm}"

s.resources = "parser/react-native-live-markdown-parser.js"

Expand All @@ -37,8 +37,10 @@ Pod::Spec.new do |s|
])
end

s.subspec "common" do |ss|
ss.source_files = "cpp/**/*.{cpp,h}"
ss.header_dir = "RNLiveMarkdown"
if ENV['RCT_NEW_ARCH_ENABLED'] == '1'
s.subspec "newarch" do |ss|
ss.source_files = "cpp/**/*.{cpp,h}"
ss.header_dir = "RNLiveMarkdown"
end
end
end
2 changes: 1 addition & 1 deletion WebExample/__tests__/styles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test.describe('markdown content styling', () => {

test('blockquote', async ({page, browserName}) => {
const blockquoteStyle =
'border-color: gray; border-width: 6px; margin-left: 6px; padding-left: 6px; border-left-style: solid; display: inline-block; max-width: 100%; box-sizing: border-box;';
'border-color: gray; border-width: 6px; margin-left: 6px; padding-left: 6px; border-left-style: solid; display: inline-block; max-width: 100%; box-sizing: border-box; overflow-wrap: anywhere;';

// Firefox border properties are serialized slightly differently
const browserStyle = browserName === 'firefox' ? blockquoteStyle.replace('border-left-style: solid', 'border-left: 6px solid gray') : blockquoteStyle;
Expand Down
4 changes: 4 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,7 @@ task copyJS(type: Copy) {
tasks.preBuild {
dependsOn copyJS
}

tasks.withType(JavaCompile).configureEach {
options.compilerArgs << "-Xlint:all" << "-Werror"
}
19 changes: 9 additions & 10 deletions android/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ find_package(fbjni REQUIRED CONFIG)
find_package(ReactAndroid REQUIRED CONFIG)
find_package(hermes-engine REQUIRED CONFIG)

target_link_libraries(
${CMAKE_PROJECT_NAME}
fbjni::fbjni
hermes-engine::libhermes
ReactAndroid::jsi
)

if (ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
target_link_libraries(${CMAKE_PROJECT_NAME}
fbjni::fbjni
ReactAndroid::jsi
ReactAndroid::reactnative
hermes-engine::libhermes)
target_link_libraries(${CMAKE_PROJECT_NAME} ReactAndroid::reactnative)
elseif (ReactAndroid_VERSION_MINOR GREATER_EQUAL 75)
target_link_libraries(${CMAKE_PROJECT_NAME}
fbjni::fbjni
ReactAndroid::jsi
ReactAndroid::reactnativejni
hermes-engine::libhermes)
target_link_libraries(${CMAKE_PROJECT_NAME} ReactAndroid::reactnativejni)
else ()
message(FATAL_ERROR "react-native-live-markdown requires react-native 0.75 or newer.")
endif ()
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static FabricUIManager create(FabricUIManager source, ReadableMap markdow
}
}

@SuppressWarnings("unchecked")
private static <T> T readPrivateField(Object obj, String name) throws NoSuchFieldException, IllegalAccessException {
Class<?> clazz = obj.getClass();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import java.util.Map;

public class LiveMarkdownPackage extends TurboReactPackage {
@NonNull
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
@SuppressWarnings("rawtypes")
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
List<ViewManager> viewManagers = new ArrayList<>();
viewManagers.add(new MarkdownTextInputDecoratorViewManager());
return viewManagers;
Expand All @@ -27,6 +29,7 @@ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext
@Override
public ReactModuleInfoProvider getReactModuleInfoProvider() {
return new ReactModuleInfoProvider() {
@NonNull
@Override
public Map<String, ReactModuleInfo> getReactModuleInfos() {
return Map.of(LiveMarkdownModule.NAME, new ReactModuleInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import androidx.annotation.NonNull;

import com.expensify.livemarkdown.spans.*;
import com.facebook.react.views.text.internal.span.CustomLineHeightSpan;
import com.facebook.soloader.SoLoader;

Expand Down Expand Up @@ -164,8 +165,6 @@ private void applyRange(SpannableStringBuilder ssb, String type, int start, int
depth);
setSpan(ssb, span, start, end);
break;
default:
throw new IllegalStateException("Unsupported type: " + type);
}
}

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

import android.text.style.BackgroundColorSpan;

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

import android.graphics.Canvas;
import android.graphics.Paint;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.expensify.livemarkdown;
package com.expensify.livemarkdown.spans;

import android.graphics.Typeface;
import android.text.style.StyleSpan;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.expensify.livemarkdown;
package com.expensify.livemarkdown.spans;

import android.text.style.AbsoluteSizeSpan;

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

import android.content.res.AssetManager;
import android.graphics.Paint;
Expand All @@ -8,8 +8,7 @@

import androidx.annotation.NonNull;

import com.facebook.react.common.assets.ReactFontManager.TypefaceStyle;
import com.facebook.react.views.text.ReactFontManager;
import com.facebook.react.common.assets.ReactFontManager;

public class MarkdownFontFamilySpan extends MetricAffectingSpan implements MarkdownSpan {

Expand All @@ -32,12 +31,7 @@ public void updateDrawState(TextPaint tp) {
}

private void apply(@NonNull TextPaint textPaint) {
int style = TypefaceStyle.NORMAL;
if (textPaint.getTypeface() != null) {
style = textPaint.getTypeface().getStyle();
} else {
style = TypefaceStyle.NORMAL;
}
int style = textPaint.getTypeface() != null ? textPaint.getTypeface().getStyle() : ReactFontManager.TypefaceStyle.NORMAL;
Typeface typeface = ReactFontManager.getInstance().getTypeface(mFontFamily, style, mAssetManager);
textPaint.setTypeface(typeface);
textPaint.setFlags(textPaint.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.expensify.livemarkdown;
package com.expensify.livemarkdown.spans;

import android.text.style.AbsoluteSizeSpan;

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

import android.text.style.ForegroundColorSpan;

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

import android.graphics.Typeface;
import android.text.style.StyleSpan;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.expensify.livemarkdown;
package com.expensify.livemarkdown.spans;

import android.graphics.Paint;
import android.text.style.LineHeightSpan;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.expensify.livemarkdown;
package com.expensify.livemarkdown.spans;

/*
* Enables us to distinguish between spans that were added by Live Markdown and spans that were
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.expensify.livemarkdown;
package com.expensify.livemarkdown.spans;

import android.text.style.StrikethroughSpan;

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

import android.text.style.UnderlineSpan;

Expand Down
Loading

0 comments on commit 39b7432

Please sign in to comment.