Skip to content

Commit f88aee7

Browse files
authored
feat(ios): support custom selection menus (#92)
1 parent eadef71 commit f88aee7

25 files changed

Lines changed: 539 additions & 54 deletions

bun.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/App.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useMemo, useState } from 'react';
22
import { ScrollView, StyleSheet, Text, View } from 'react-native';
33
import { NitroText, TextLayoutEvent } from 'react-native-nitro-text';
44

@@ -17,6 +17,14 @@ export default function App() {
1717
// setLayoutInfo(`Lines: ${lines.length}`);
1818
};
1919

20+
const menus = useMemo(
21+
() => [
22+
{ title: 'Ask ChatGPT', action: () => console.log('Ask ChatGPT') },
23+
{ title: 'Paste', action: () => console.log('Paste') },
24+
],
25+
[],
26+
);
27+
2028
return (
2129
<ScrollView style={styles.container} contentContainerStyle={styles.content}>
2230
{/* Header Section */}
@@ -61,7 +69,7 @@ export default function App() {
6169
{/* Rich Text Formatting */}
6270
<View style={styles.section}>
6371
<NitroText style={styles.sectionTitle}>Rich Text Formatting</NitroText>
64-
<NitroText style={styles.richText}>
72+
<NitroText selectable menus={menus} style={styles.richText}>
6573
Welcome to the world of{' '}
6674
<NitroText style={styles.bold}>bold text</NitroText>,{' '}
6775
<NitroText style={styles.italic}>beautiful italics</NitroText>, and{' '}
@@ -129,7 +137,11 @@ export default function App() {
129137
<View style={styles.section}>
130138
<NitroText style={styles.sectionTitle}>Line Limiting</NitroText>
131139
<NitroText style={styles.description}>Two lines maximum:</NitroText>
132-
<NitroText style={styles.limitedText} numberOfLines={2} ellipsizeMode='tail'>
140+
<NitroText
141+
style={styles.limitedText}
142+
numberOfLines={2}
143+
ellipsizeMode="tail"
144+
>
133145
This is a very long text that would normally span multiple lines, but
134146
we're limiting it to just two lines. The text will be truncated with
135147
an ellipsis when it exceeds the specified number of lines. This is

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PODS:
88
- hermes-engine (0.81.4):
99
- hermes-engine/Pre-built (= 0.81.4)
1010
- hermes-engine/Pre-built (0.81.4)
11-
- NitroModules (0.30.0):
11+
- NitroModules (0.31.2):
1212
- boost
1313
- DoubleConversion
1414
- fast_float
@@ -2643,7 +2643,7 @@ SPEC CHECKSUMS:
26432643
fmt: a40bb5bd0294ea969aaaba240a927bd33d878cdd
26442644
glog: 5683914934d5b6e4240e497e0f4a3b42d1854183
26452645
hermes-engine: 35c763d57c9832d0eef764316ca1c4d043581394
2646-
NitroModules: dae5a0f5867aa19ca3222084519c30cb6ca0280a
2646+
NitroModules: 2862238ccf1a30c3e3c20fb10ae297ce26168718
26472647
NitroText: c95604214333634a6a083ac7211b238686dbd628
26482648
RCT-Folly: 846fda9475e61ec7bcbf8a3fe81edfcaeb090669
26492649
RCTDeprecation: c0ed3249a97243002615517dff789bf4666cf585

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"react": "19.1.0",
1515
"react-native": "0.81.4",
1616
"react-native-safe-area-context": "^5.5.2",
17-
"react-native-nitro-modules": "^0.30.0"
17+
"react-native-nitro-modules": "^0.31.2"
1818
},
1919
"devDependencies": {
2020
"@babel/core": "^7.25.2",

ios/HybridNitroText.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ class HybridNitroText: HybridNitroTextSpec, NitroTextViewDelegate {
177177
markNeedsApply()
178178
}
179179
}
180+
181+
var menus: [MenuItem]? {
182+
didSet {
183+
nitroTextImpl.setMenus(menus ?? [])
184+
}
185+
}
180186

181187
// Merge per-fragment props with top-level fallbacks and apply (delegated to NitroTextImpl)
182188
private func applyFragmentsAndProps() {

ios/NitroTextImpl.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ final class NitroTextImpl {
224224

225225
setText(result)
226226
}
227+
228+
func setMenus(_ menus: [MenuItem]) {
229+
nitroTextView?.customMenus = menus
230+
}
227231
}
228232

229233
extension NitroTextImpl {

0 commit comments

Comments
 (0)