Skip to content

Commit a4972a0

Browse files
authored
Merge branch 'main' into add-imperative-html-method
2 parents 088b596 + f7bdf9e commit a4972a0

74 files changed

Lines changed: 5865 additions & 3801 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ jobs:
2020
- name: Setup
2121
uses: ./.github/actions/setup
2222

23-
- name: Lint files
23+
- name: Run ESLint (JS/TS)
2424
run: yarn lint
2525

26+
- name: Run clang-format (C/C++ style check)
27+
run: yarn lint-clang
28+
2629
- name: Typecheck files
2730
run: yarn typecheck
2831

README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<img src="https://github.com/user-attachments/assets/abc75d3b-495b-4a76-a72f-d87ce3ca1ff9" alt="react-native-enriched by Software Mansion" width="100%">
1+
<img src="https://github.com/user-attachments/assets/b010571e-e4a3-4d92-a409-4f9fe614025d" alt="react-native-enriched by Software Mansion" width="100%">
22

33
# react-native-enriched
44

@@ -40,7 +40,7 @@ We can help you build your next dream product –
4040
## Prerequisites
4141

4242
- `react-native-enriched` currently supports only Android and iOS platforms
43-
- It works only with [the React Native New Architecture (Fabric)](https://reactnative.dev/architecture/landing-page) and supports following React Native releases: `0.79`, `0.80`, `0.81` and `0.82`
43+
- It works only with [the React Native New Architecture (Fabric)](https://reactnative.dev/architecture/landing-page) and supports following React Native releases: `0.79`, `0.80`, `0.81`, `0.82` and `0.83`
4444

4545
## Installation
4646

@@ -152,9 +152,6 @@ Supported styles:
152152
- ordered list
153153
- unordered list
154154

155-
> [!NOTE]
156-
> The iOS doesn't support codeblocks just yet, but it's planned in the near future!
157-
158155
Each of the styles can be toggled the same way as in the example from [usage section](#usage); call a proper `toggle` function on the component ref.
159156

160157
Each call toggles the style within the current text selection. We can still divide styles into two categories based on how they treat the selection:
@@ -212,9 +209,6 @@ You can insert an image into the input using [setImage](docs/API_REFERENCE.md#se
212209

213210
The image will be put into a single line in the input and will affect the line's height as well as input's height. Keep in mind, that image will replace currently selected text or insert into the cursor position if there is no text selection.
214211

215-
> [!NOTE]
216-
> The iOS doesn't support inline images just yet, but it's planned in the near future!
217-
218212
## Style Detection
219213

220214
All of the above styles can be detected with the use of [onChangeState](docs/API_REFERENCE.md#onchangestate) event payload.

android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class MentionHandler(private val view: EnrichedTextInputView) {
99
private var previousIndicator: String? = null
1010

1111
fun reset() {
12+
endMention()
1213
previousText = null
13-
previousIndicator = null
1414
}
1515

1616
fun endMention() {

android/src/main/java/com/swmansion/enriched/styles/InlineStyles.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.swmansion.enriched.styles
22

33
import android.text.Editable
44
import android.text.Spannable
5-
import android.util.Log
65
import com.swmansion.enriched.EnrichedTextInputView
76
import com.swmansion.enriched.spans.EnrichedSpans
87
import com.swmansion.enriched.utils.getSafeSpanBoundaries
@@ -57,6 +56,8 @@ class InlineStyles(private val view: EnrichedTextInputView) {
5756
var finalEnd: Int? = null
5857
if (spanStart == -1 || spanEnd == -1) continue
5958

59+
spannable.removeSpan(span)
60+
6061
if (start == spanStart && end == spanEnd) {
6162
setSpanOnFinish = false
6263
} else if (start > spanStart && end < spanEnd) {

android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ParagraphStyles(private val view: EnrichedTextInputView) {
6767
spannable.removeSpan(previousSpan)
6868
}
6969

70-
if (nextSpan != null) {
70+
if (nextSpan != null && start != end) {
7171
newEnd = spannable.getSpanEnd(nextSpan)
7272
spannable.removeSpan(nextSpan)
7373
}

android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11

22
/**
3-
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3+
* This code was generated by
4+
* [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
45
*
5-
* Do not edit this file as changes may cause incorrect behavior and will be lost
6-
* once the code is regenerated.
6+
* Do not edit this file as changes may cause incorrect behavior and will be
7+
* lost once the code is regenerated.
78
*
89
* @generated by codegen project: GenerateModuleJniCpp.js
910
*/
@@ -12,9 +13,8 @@
1213

1314
namespace facebook::react {
1415

15-
16-
17-
std::shared_ptr<TurboModule> RNEnrichedTextInputViewSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {
16+
std::shared_ptr<TurboModule> RNEnrichedTextInputViewSpec_ModuleProvider(
17+
const std::string &moduleName, const JavaTurboModule::InitParams &params) {
1818

1919
return nullptr;
2020
}

android/src/main/new_arch/RNEnrichedTextInputViewSpec.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11

22
/**
3-
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3+
* This code was generated by
4+
* [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
45
*
5-
* Do not edit this file as changes may cause incorrect behavior and will be lost
6-
* once the code is regenerated.
6+
* Do not edit this file as changes may cause incorrect behavior and will be
7+
* lost once the code is regenerated.
78
*
89
* @generated by codegen project: GenerateModuleJniH.js
910
*/
@@ -18,9 +19,8 @@
1819

1920
namespace facebook::react {
2021

21-
22-
2322
JSI_EXPORT
24-
std::shared_ptr<TurboModule> RNEnrichedTextInputViewSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);
23+
std::shared_ptr<TurboModule> RNEnrichedTextInputViewSpec_ModuleProvider(
24+
const std::string &moduleName, const JavaTurboModule::InitParams &params);
2525

2626
} // namespace facebook::react

android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputComponentDescriptor.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@
88
namespace facebook::react {
99

1010
class EnrichedTextInputComponentDescriptor final
11-
: public ConcreteComponentDescriptor<EnrichedTextInputShadowNode> {
11+
: public ConcreteComponentDescriptor<EnrichedTextInputShadowNode> {
1212
public:
13-
EnrichedTextInputComponentDescriptor(
14-
const ComponentDescriptorParameters& parameters)
15-
: ConcreteComponentDescriptor(parameters),
16-
measurementsManager_(
17-
std::make_shared<EnrichedTextInputMeasurementManager>(
18-
contextContainer_)) {}
19-
20-
void adopt(ShadowNode& shadowNode) const override {
21-
ConcreteComponentDescriptor::adopt(shadowNode);
22-
auto& editorShadowNode = static_cast<EnrichedTextInputShadowNode&>(shadowNode);
23-
24-
// `EnrichedTextInputShadowNode` uses
25-
// `EnrichedTextInputMeasurementManager` to provide measurements to Yoga.
26-
editorShadowNode.setMeasurementsManager(measurementsManager_);
27-
}
13+
EnrichedTextInputComponentDescriptor(
14+
const ComponentDescriptorParameters &parameters)
15+
: ConcreteComponentDescriptor(parameters),
16+
measurementsManager_(
17+
std::make_shared<EnrichedTextInputMeasurementManager>(
18+
contextContainer_)) {}
19+
20+
void adopt(ShadowNode &shadowNode) const override {
21+
ConcreteComponentDescriptor::adopt(shadowNode);
22+
auto &editorShadowNode =
23+
static_cast<EnrichedTextInputShadowNode &>(shadowNode);
24+
25+
// `EnrichedTextInputShadowNode` uses
26+
// `EnrichedTextInputMeasurementManager` to provide measurements to Yoga.
27+
editorShadowNode.setMeasurementsManager(measurementsManager_);
28+
}
2829

2930
private:
30-
const std::shared_ptr<EnrichedTextInputMeasurementManager>
31-
measurementsManager_;
31+
const std::shared_ptr<EnrichedTextInputMeasurementManager>
32+
measurementsManager_;
3233
};
3334

3435
} // namespace facebook::react
35-

android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.cpp

Lines changed: 40 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,45 @@ using namespace facebook::jni;
99

1010
namespace facebook::react {
1111

12-
Size EnrichedTextInputMeasurementManager::measure(
13-
SurfaceId surfaceId,
14-
int viewTag,
15-
const EnrichedTextInputViewProps& props,
16-
LayoutConstraints layoutConstraints) const {
17-
const jni::global_ref<jobject>& fabricUIManager =
18-
contextContainer_->at<jni::global_ref<jobject>>("FabricUIManager");
19-
20-
static const auto measure = facebook::jni::findClassStatic(
21-
"com/facebook/react/fabric/FabricUIManager")
22-
->getMethod<jlong(
23-
jint,
24-
jstring,
25-
ReadableMap::javaobject,
26-
ReadableMap::javaobject,
27-
ReadableMap::javaobject,
28-
jfloat,
29-
jfloat,
30-
jfloat,
31-
jfloat)>("measure");
32-
33-
auto minimumSize = layoutConstraints.minimumSize;
34-
auto maximumSize = layoutConstraints.maximumSize;
35-
36-
local_ref<JString> componentName = make_jstring("EnrichedTextInputView");
37-
38-
// Prepare extraData map with viewTag
39-
folly::dynamic extraData = folly::dynamic::object();
40-
extraData["viewTag"] = viewTag;
41-
local_ref<ReadableNativeMap::javaobject> extraDataRNM = ReadableNativeMap::newObjectCxxArgs(extraData);
42-
local_ref<ReadableMap::javaobject> extraDataRM = make_local(reinterpret_cast<ReadableMap::javaobject>(extraDataRNM.get()));
43-
44-
// Prepare layout metrics affecting props
45-
auto serializedProps = toDynamic(props);
46-
local_ref<ReadableNativeMap::javaobject> propsRNM = ReadableNativeMap::newObjectCxxArgs(serializedProps);
47-
local_ref<ReadableMap::javaobject> propsRM = make_local(reinterpret_cast<ReadableMap::javaobject>(propsRNM.get()));
48-
49-
auto measurement = yogaMeassureToSize(measure(
50-
fabricUIManager,
51-
surfaceId,
52-
componentName.get(),
53-
extraDataRM.get(),
54-
propsRM.get(),
55-
nullptr,
56-
minimumSize.width,
57-
maximumSize.width,
58-
minimumSize.height,
59-
maximumSize.height));
60-
61-
return measurement;
62-
}
12+
Size EnrichedTextInputMeasurementManager::measure(
13+
SurfaceId surfaceId, int viewTag, const EnrichedTextInputViewProps &props,
14+
LayoutConstraints layoutConstraints) const {
15+
const jni::global_ref<jobject> &fabricUIManager =
16+
contextContainer_->at<jni::global_ref<jobject>>("FabricUIManager");
17+
18+
static const auto measure =
19+
facebook::jni::findClassStatic(
20+
"com/facebook/react/fabric/FabricUIManager")
21+
->getMethod<jlong(jint, jstring, ReadableMap::javaobject,
22+
ReadableMap::javaobject, ReadableMap::javaobject,
23+
jfloat, jfloat, jfloat, jfloat)>("measure");
24+
25+
auto minimumSize = layoutConstraints.minimumSize;
26+
auto maximumSize = layoutConstraints.maximumSize;
27+
28+
local_ref<JString> componentName = make_jstring("EnrichedTextInputView");
29+
30+
// Prepare extraData map with viewTag
31+
folly::dynamic extraData = folly::dynamic::object();
32+
extraData["viewTag"] = viewTag;
33+
local_ref<ReadableNativeMap::javaobject> extraDataRNM =
34+
ReadableNativeMap::newObjectCxxArgs(extraData);
35+
local_ref<ReadableMap::javaobject> extraDataRM =
36+
make_local(reinterpret_cast<ReadableMap::javaobject>(extraDataRNM.get()));
37+
38+
// Prepare layout metrics affecting props
39+
auto serializedProps = toDynamic(props);
40+
local_ref<ReadableNativeMap::javaobject> propsRNM =
41+
ReadableNativeMap::newObjectCxxArgs(serializedProps);
42+
local_ref<ReadableMap::javaobject> propsRM =
43+
make_local(reinterpret_cast<ReadableMap::javaobject>(propsRNM.get()));
44+
45+
auto measurement = yogaMeassureToSize(
46+
measure(fabricUIManager, surfaceId, componentName.get(),
47+
extraDataRM.get(), propsRM.get(), nullptr, minimumSize.width,
48+
maximumSize.width, minimumSize.height, maximumSize.height));
49+
50+
return measurement;
51+
}
6352

6453
} // namespace facebook::react

android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@
22

33
#include "ComponentDescriptors.h"
44

5-
#include <react/utils/ContextContainer.h>
6-
#include <react/renderer/core/LayoutConstraints.h>
75
#include <react/renderer/components/RNEnrichedTextInputViewSpec/Props.h>
6+
#include <react/renderer/core/LayoutConstraints.h>
7+
#include <react/utils/ContextContainer.h>
88

99
namespace facebook::react {
1010

11-
class EnrichedTextInputMeasurementManager {
12-
public:
13-
EnrichedTextInputMeasurementManager(
14-
const std::shared_ptr<const ContextContainer>& contextContainer)
15-
: contextContainer_(contextContainer) {}
11+
class EnrichedTextInputMeasurementManager {
12+
public:
13+
EnrichedTextInputMeasurementManager(
14+
const std::shared_ptr<const ContextContainer> &contextContainer)
15+
: contextContainer_(contextContainer) {}
1616

17-
Size measure(
18-
SurfaceId surfaceId,
19-
int viewTag,
20-
const EnrichedTextInputViewProps& props,
21-
LayoutConstraints layoutConstraints) const;
17+
Size measure(SurfaceId surfaceId, int viewTag,
18+
const EnrichedTextInputViewProps &props,
19+
LayoutConstraints layoutConstraints) const;
2220

23-
private:
24-
const std::shared_ptr<const ContextContainer> contextContainer_;
25-
};
21+
private:
22+
const std::shared_ptr<const ContextContainer> contextContainer_;
23+
};
2624

2725
} // namespace facebook::react

0 commit comments

Comments
 (0)