-
Notifications
You must be signed in to change notification settings - Fork 78
feat(ios): add image support to input #403
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
Draft
hryhoriiK97
wants to merge
3
commits into
main
Choose a base branch
from
feat/image-input-ios
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
0f9eb54
feat(ios): add image support to input — store, paste, serialize, and …
hryhoriiK97 251a284
Merge remote-tracking branch 'origin' into feat/image-input-ios
hryhoriiK97 306eb8a
fix(ios): enhance image attachment key generation and improve image e…
hryhoriiK97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/react-native-enriched-markdown/ios/input/ENRMEditAdjusting.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #pragma once | ||
| #import <Foundation/Foundation.h> | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| @protocol ENRMEditAdjusting <NSObject> | ||
|
|
||
| - (void)adjustForEditAtLocation:(NSUInteger)location | ||
| deletedLength:(NSUInteger)deletedLength | ||
| insertedLength:(NSUInteger)insertedLength; | ||
| - (void)clearAll; | ||
|
|
||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END |
3 changes: 2 additions & 1 deletion
3
packages/react-native-enriched-markdown/ios/input/ENRMFormattingStore.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/react-native-enriched-markdown/ios/input/ENRMImageStore.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #pragma once | ||
|
|
||
| #import "ENRMEditAdjusting.h" | ||
| #import <Foundation/Foundation.h> | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| @interface ENRMImageEntry : NSObject | ||
|
|
||
| @property (nonatomic, assign) NSUInteger position; | ||
| @property (nonatomic, copy) NSString *url; | ||
| @property (nonatomic, copy) NSString *alt; | ||
| @property (nonatomic, assign) CGFloat width; | ||
| @property (nonatomic, assign) CGFloat height; | ||
| @property (nonatomic, assign) BOOL isInline; | ||
|
|
||
| + (instancetype)entryWithPosition:(NSUInteger)position | ||
| url:(NSString *)url | ||
| alt:(NSString *)alt | ||
| width:(CGFloat)width | ||
| height:(CGFloat)height | ||
| isInline:(BOOL)isInline; | ||
|
|
||
| @end | ||
|
|
||
| @interface ENRMImageStore : NSObject <ENRMEditAdjusting> | ||
|
|
||
| @property (nonatomic, readonly) NSArray<ENRMImageEntry *> *allEntries; | ||
|
|
||
| - (void)addEntry:(ENRMImageEntry *)entry; | ||
| - (void)removeEntryAtPosition:(NSUInteger)position; | ||
| - (nullable ENRMImageEntry *)entryAtPosition:(NSUInteger)position; | ||
| - (void)clearAll; | ||
|
|
||
| - (void)adjustForEditAtLocation:(NSUInteger)editLocation | ||
| deletedLength:(NSUInteger)deletedLength | ||
| insertedLength:(NSUInteger)insertedLength; | ||
|
|
||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END |
112 changes: 112 additions & 0 deletions
112
packages/react-native-enriched-markdown/ios/input/ENRMImageStore.mm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| #import "ENRMImageStore.h" | ||
|
|
||
| @implementation ENRMImageEntry | ||
|
|
||
| + (instancetype)entryWithPosition:(NSUInteger)position | ||
| url:(NSString *)url | ||
| alt:(NSString *)alt | ||
| width:(CGFloat)width | ||
| height:(CGFloat)height | ||
| isInline:(BOOL)isInline | ||
| { | ||
| ENRMImageEntry *entry = [[ENRMImageEntry alloc] init]; | ||
| entry.position = position; | ||
| entry.url = url; | ||
| entry.alt = alt; | ||
| entry.width = width; | ||
| entry.height = height; | ||
| entry.isInline = isInline; | ||
| return entry; | ||
| } | ||
|
|
||
| @end | ||
|
|
||
| @implementation ENRMImageStore { | ||
| NSMutableArray<ENRMImageEntry *> *_entries; | ||
| } | ||
|
|
||
| - (instancetype)init | ||
| { | ||
| if (self = [super init]) { | ||
| _entries = [NSMutableArray array]; | ||
| } | ||
| return self; | ||
| } | ||
|
|
||
| - (NSArray<ENRMImageEntry *> *)allEntries | ||
| { | ||
| return [_entries copy]; | ||
| } | ||
|
|
||
| - (void)addEntry:(ENRMImageEntry *)entry | ||
| { | ||
| NSUInteger insertAt = 0; | ||
| for (NSUInteger i = 0; i < _entries.count; i++) { | ||
| if (_entries[i].position == entry.position) { | ||
| _entries[i] = entry; | ||
| return; | ||
| } | ||
| if (_entries[i].position > entry.position) | ||
| break; | ||
| insertAt = i + 1; | ||
| } | ||
| [_entries insertObject:entry atIndex:insertAt]; | ||
| } | ||
|
|
||
| - (void)removeEntryAtPosition:(NSUInteger)position | ||
| { | ||
| for (NSUInteger i = 0; i < _entries.count; i++) { | ||
| if (_entries[i].position == position) { | ||
| [_entries removeObjectAtIndex:i]; | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| - (nullable ENRMImageEntry *)entryAtPosition:(NSUInteger)position | ||
| { | ||
| for (ENRMImageEntry *entry in _entries) { | ||
| if (entry.position == position) { | ||
| return entry; | ||
| } | ||
| } | ||
| return nil; | ||
| } | ||
|
|
||
| - (void)clearAll | ||
| { | ||
| [_entries removeAllObjects]; | ||
| } | ||
|
|
||
| - (void)adjustForEditAtLocation:(NSUInteger)editLocation | ||
| deletedLength:(NSUInteger)deletedLength | ||
| insertedLength:(NSUInteger)insertedLength | ||
| { | ||
| if (deletedLength == 0 && insertedLength == 0) | ||
| return; | ||
|
|
||
| NSUInteger deleteEnd = editLocation + deletedLength; | ||
| NSMutableIndexSet *indexesToRemove = [NSMutableIndexSet indexSet]; | ||
|
|
||
| for (NSUInteger i = 0; i < _entries.count; i++) { | ||
| ENRMImageEntry *entry = _entries[i]; | ||
| NSUInteger pos = entry.position; | ||
|
|
||
| if (deletedLength > 0) { | ||
| if (pos >= editLocation && pos < deleteEnd) { | ||
| [indexesToRemove addIndex:i]; | ||
| } else if (pos >= deleteEnd) { | ||
| entry.position = pos - deletedLength + insertedLength; | ||
| } | ||
| } else { | ||
| if (pos >= editLocation) { | ||
| entry.position = pos + insertedLength; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [indexesToRemove enumerateIndexesWithOptions:NSEnumerationReverse | ||
| usingBlock:^(NSUInteger idx, BOOL *stop) { [_entries removeObjectAtIndex:idx]; }]; | ||
| } | ||
|
|
||
| @end |
7 changes: 1 addition & 6 deletions
7
packages/react-native-enriched-markdown/ios/input/ENRMInputParser.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.