Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: composer not cleared when sending message #44285

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
2828112
add patch
hannojg Jun 24, 2024
97769d3
wip
hannojg Jun 24, 2024
cf0ad39
wip
hannojg Jun 25, 2024
b78967e
Merge branch 'main' of github.com:Expensify/App into fix/composer-not…
hannojg Jun 25, 2024
a0c387c
wip: fix typing comment
hannojg Jun 25, 2024
6aa7df5
minor cleanup
hannojg Jun 26, 2024
add1df6
wip: restore functionality, but broken:
hannojg Jun 26, 2024
d9f197e
fix inserting emojis via colon is broken
hannojg Jun 26, 2024
87a286e
add todo
hannojg Jun 26, 2024
5b89d05
removed migrated onTextChange
hannojg Jun 26, 2024
d8fdf33
rename to handleInputChange
hannojg Jun 26, 2024
da9d7b2
update isCommentEmpty from effect
hannojg Jun 26, 2024
d4927cb
fix: remove unused setValue props from Suggestions
hannojg Jun 26, 2024
6715b48
fix updateComment in SilentCommentUpdater to update text input directly
hannojg Jun 26, 2024
6c49d98
fix use case of replaceSelectionWithText
hannojg Jun 26, 2024
d8f8147
rename to handleComposerUpdate
hannojg Jun 26, 2024
97ef3bb
explain it a bit better
hannojg Jun 26, 2024
fd5b913
migrated Suggestions to new composer API using handleComposerUpdate
hannojg Jun 26, 2024
bc3add2
cleanup
hannojg Jun 26, 2024
33bfda5
remove debug code
hannojg Jun 26, 2024
3aaef88
fix bug: type, send, text reappears
hannojg Jun 27, 2024
130a41a
fix draft comment not being cleared when sending
hannojg Jun 27, 2024
97d965b
Merge branch 'main' of github.com:Expensify/App into fix/composer-not…
hannojg Jun 27, 2024
eca8677
provide web patch
hannojg Jun 27, 2024
0904ac6
fix: pressing send not working on web
hannojg Jun 28, 2024
1bc30e6
add comment updater back
hannojg Jun 28, 2024
1d56523
Merge branch 'main' of github.com:Expensify/App into fix/composer-not…
hannojg Jul 1, 2024
a27219d
fix bugs during deleting/replacing on web
hannojg Jul 1, 2024
b933802
fix backwards delete
hannojg Jul 1, 2024
c3a40d6
web: fix deleting all content
hannojg Jul 1, 2024
2285a53
fix deleting not working properly
hannojg Jul 1, 2024
f3251b8
fix web inserting emojis selection was off
hannojg Jul 1, 2024
5b32732
remove unused dep
hannojg Jul 1, 2024
5417cfb
web: fix deleting multi-character glyphs
hannojg Jul 2, 2024
a982d2f
remove debug log
hannojg Jul 2, 2024
b929348
remove half-bakes cosmetic changes
hannojg Jul 2, 2024
305882e
add comments + prettier format
hannojg Jul 2, 2024
a1d1aa9
ran prettier
hannojg Jul 2, 2024
d0cb9e7
Merge branch 'main' of github.com:margelo/expensify-app-fork into fix…
hannojg Jul 5, 2024
ea2889c
fix: deleting text then writing is buggy
hannojg Jul 5, 2024
1fc7285
remove handlePaste change
hannojg Jul 5, 2024
c489b4b
fix eslint
hannojg Jul 5, 2024
05c617f
Merge branch 'main' of github.com:Expensify/App into fix/composer-not…
hannojg Jul 9, 2024
4973d78
Merge branch 'main' of github.com:Expensify/App into fix/composer-not…
hannojg Jul 16, 2024
e8f8e0a
remove unused code
hannojg Jul 16, 2024
9f5fa16
delete now included patch
hannojg Jul 16, 2024
a3fb1a3
fix Suggestion usage in message edit
hannojg Jul 16, 2024
32ac0de
ran prettier
hannojg Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions patches/react-native+0.73.4+017.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
diff --git a/node_modules/react-native/Libraries/Components/TextInput/TextInput.d.ts b/node_modules/react-native/Libraries/Components/TextInput/TextInput.d.ts
index 2c0c099..472877a 100644
--- a/node_modules/react-native/Libraries/Components/TextInput/TextInput.d.ts
+++ b/node_modules/react-native/Libraries/Components/TextInput/TextInput.d.ts
@@ -451,6 +451,9 @@ export interface TextInputKeyPressEventData {
export interface TextInputChangeEventData extends TargetedEvent {
eventCount: number;
text: string;
+ before: number;
+ start: number;
+ count: number;
}

/**
diff --git a/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm
index 7ce04da..b7c3b6f 100644
--- a/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm
+++ b/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm
@@ -55,6 +55,10 @@ @implementation RCTTextInputComponentView {
*/
BOOL _comingFromJS;
BOOL _didMoveToWindow;
+
+ NSInteger changeStart;
+ NSInteger changeBefore;
+ NSInteger changeCount;
}

#pragma mark - UIView overrides
@@ -344,6 +348,10 @@ - (NSString *)textInputShouldChangeText:(NSString *)text inRange:(NSRange)range
{
const auto &props = static_cast<const TextInputProps &>(*_props);

+ changeStart = range.location;
+ changeBefore = range.length;
+ changeCount = text.length;
+
if (!_backedTextInputView.textWasPasted) {
if (_eventEmitter) {
KeyPressMetrics keyPressMetrics;
@@ -540,6 +548,9 @@ - (TextInputMetrics)_textInputMetrics
metrics.text = RCTStringFromNSString(_backedTextInputView.attributedText.string);
metrics.selectionRange = [self _selectionRange];
metrics.eventCount = _mostRecentEventCount;
+ metrics.count = static_cast<int>(changeCount);
+ metrics.before = static_cast<int>(changeBefore);
+ metrics.start = static_cast<int>(changeStart);

CGPoint contentOffset = _backedTextInputView.contentOffset;
metrics.contentOffset = {contentOffset.x, contentOffset.y};
diff --git a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextChangedEvent.java b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextChangedEvent.java
index 4540b90..c44a11f 100644
--- a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextChangedEvent.java
+++ b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextChangedEvent.java
@@ -23,16 +23,23 @@ public class ReactTextChangedEvent extends Event<ReactTextChangedEvent> {

private String mText;
private int mEventCount;
+ // See https://developer.android.com/reference/android/text/TextWatcher#onTextChanged(java.lang.CharSequence,%20int,%20int,%20int)
+ private int mStart;
+ private int mCount;
+ private int mBefore;

@Deprecated
- public ReactTextChangedEvent(int viewId, String text, int eventCount) {
- this(ViewUtil.NO_SURFACE_ID, viewId, text, eventCount);
+ public ReactTextChangedEvent(int viewId, String text, int eventCount, int start, int count, int before) {
+ this(ViewUtil.NO_SURFACE_ID, viewId, text, eventCount, start, count, before);
}

- public ReactTextChangedEvent(int surfaceId, int viewId, String text, int eventCount) {
+ public ReactTextChangedEvent(int surfaceId, int viewId, String text, int eventCount, int start, int count, int before) {
super(surfaceId, viewId);
mText = text;
mEventCount = eventCount;
+ mStart = start;
+ mCount = count;
+ mBefore = before;
}

@Override
@@ -47,6 +54,9 @@ public class ReactTextChangedEvent extends Event<ReactTextChangedEvent> {
eventData.putString("text", mText);
eventData.putInt("eventCount", mEventCount);
eventData.putInt("target", getViewTag());
+ eventData.putInt("start", mStart);
+ eventData.putInt("count", mCount);
+ eventData.putInt("before", mBefore);
return eventData;
}
}
diff --git a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java
index 8496a7d..fd5076b 100644
--- a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java
+++ b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java
@@ -1068,7 +1068,12 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
mSurfaceId,
mEditText.getId(),
s.toString(),
- mEditText.incrementAndGetEventCounter()));
+ mEditText.incrementAndGetEventCounter(),
+ start,
+ count,
+ before
+ )
+ );

mEventDispatcher.dispatchEvent(
new ReactTextInputEvent(
diff --git a/node_modules/react-native/ReactCommon/react/renderer/components/textinput/iostextinput/react/renderer/components/iostextinput/TextInputEventEmitter.cpp b/node_modules/react-native/ReactCommon/react/renderer/components/textinput/iostextinput/react/renderer/components/iostextinput/TextInputEventEmitter.cpp
index 497569a..f1c189c 100644
--- a/node_modules/react-native/ReactCommon/react/renderer/components/textinput/iostextinput/react/renderer/components/iostextinput/TextInputEventEmitter.cpp
+++ b/node_modules/react-native/ReactCommon/react/renderer/components/textinput/iostextinput/react/renderer/components/iostextinput/TextInputEventEmitter.cpp
@@ -20,6 +20,9 @@ static jsi::Value textInputMetricsPayload(
jsi::String::createFromUtf8(runtime, textInputMetrics.text));

payload.setProperty(runtime, "eventCount", textInputMetrics.eventCount);
+ payload.setProperty(runtime, "start", textInputMetrics.start);
+ payload.setProperty(runtime, "count", textInputMetrics.count);
+ payload.setProperty(runtime, "before", textInputMetrics.before);

{
auto selection = jsi::Object(runtime);
diff --git a/node_modules/react-native/ReactCommon/react/renderer/components/textinput/iostextinput/react/renderer/components/iostextinput/TextInputEventEmitter.h b/node_modules/react-native/ReactCommon/react/renderer/components/textinput/iostextinput/react/renderer/components/iostextinput/TextInputEventEmitter.h
index 0ab2b18..42a4fd6 100644
--- a/node_modules/react-native/ReactCommon/react/renderer/components/textinput/iostextinput/react/renderer/components/iostextinput/TextInputEventEmitter.h
+++ b/node_modules/react-native/ReactCommon/react/renderer/components/textinput/iostextinput/react/renderer/components/iostextinput/TextInputEventEmitter.h
@@ -16,6 +16,9 @@ class TextInputMetrics {
public:
std::string text;
AttributedString::Range selectionRange;
+ int count;
+ int start;
+ int before;
// ScrollView-like metrics
Size contentSize;
Point contentOffset;
4 changes: 2 additions & 2 deletions src/components/Composer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,14 @@ function Composer(
autoCorrect={!Browser.isMobileSafari()}
placeholderTextColor={theme.placeholderText}
ref={(el) => (textInput.current = el)}
selection={selection}
style={[inputStyleMemo]}
style={inputStyleMemo}
markdownStyle={markdownStyle}
value={value}
defaultValue={defaultValue}
autoFocus={autoFocus}
/* eslint-disable-next-line react/jsx-props-no-spreading */
{...props}
selection={selection}
onSelectionChange={addCursorPositionToSelectionChange}
onContentSizeChange={(e) => {
setTextInputWidth(`${e.nativeEvent.contentSize.width}px`);
Expand Down
24 changes: 23 additions & 1 deletion src/libs/SuggestionUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type {TextSelection} from '@components/Composer/types';
import type {HandleComposerUpdateArgs} from '@pages/home/report/ReportActionCompose/ComposerWithSuggestions/types';
import CONST from '@src/CONST';

/**
Expand All @@ -20,4 +22,24 @@ function hasEnoughSpaceForLargeSuggestionMenu(listHeight: number, composerHeight
return availableHeight > menuHeight;
}

export {trimLeadingSpace, hasEnoughSpaceForLargeSuggestionMenu};
/**
* Replaces the selection range in currentText with the insert value
*/
function getComposerUpdateArgsForSuggestionToInsert(currentText: string, insert: string, selection: TextSelection): HandleComposerUpdateArgs {
const textBefore = currentText.slice(0, selection.start);
const textAfter = currentText.slice(selection.end);

const newText = `${insert} `;
const firstPart = textBefore + newText;
const fullNewText = firstPart + trimLeadingSpace(textAfter);
const endPosition = firstPart.length;

return {
diffText: newText,
fullNewText,
endPositionOfNewAddedText: endPosition,
shouldDebounceSaveComment: true,
};
}

export {trimLeadingSpace, hasEnoughSpaceForLargeSuggestionMenu, getComposerUpdateArgsForSuggestionToInsert};
Loading
Loading