rn-rich-text-editor 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Toolbar.js +66 -79
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-rich-text-editor",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "A rich text editor component for React Native",
5
5
  "keywords": [
6
6
  "react-native",
package/src/Toolbar.js CHANGED
@@ -6,19 +6,13 @@ const FADE_WIDTH = 24;
6
6
  const FADE_STRIPS = 5;
7
7
  const TOOLBAR_BG = '#efefef';
8
8
 
9
- function hexToRgb(hex) {
10
- const match = hex.replace('#', '').match(/.{2}/g);
11
- return match ? match.map((x) => parseInt(x, 16)) : [239, 239, 239];
12
- }
9
+ const FADE_OPACITY_MIN = 0.4; // 40% - #FFFFFF66
10
+ const FADE_OPACITY_MAX = 0.76; // 76%
13
11
 
14
- function FadeOverlay({ side, visible, backgroundColor }) {
12
+ function FadeOverlay({ side, visible }) {
15
13
  if (!visible) return null;
16
- const bg = backgroundColor || TOOLBAR_BG;
17
- const rgb = bg.startsWith('rgb')
18
- ? bg.match(/\d+/g)?.map(Number) || [239, 239, 239]
19
- : hexToRgb(bg);
20
14
  const strips = Array.from({ length: FADE_STRIPS }, (_, i) => {
21
- const alpha = ((i + 1) / FADE_STRIPS) * 0.85;
15
+ const alpha = FADE_OPACITY_MIN + (i / (FADE_STRIPS - 1)) * (FADE_OPACITY_MAX - FADE_OPACITY_MIN);
22
16
  const stripWidth = FADE_WIDTH / FADE_STRIPS;
23
17
  return (
24
18
  <View
@@ -27,7 +21,7 @@ function FadeOverlay({ side, visible, backgroundColor }) {
27
21
  styles.fadeStrip,
28
22
  {
29
23
  width: stripWidth,
30
- backgroundColor: `rgba(${rgb[0]}, ${rgb[1]}, ${rgb[2]}, ${alpha})`,
24
+ backgroundColor: `rgba(255, 255, 255, ${alpha})`,
31
25
  left: side === 'left' ? FADE_WIDTH - (i + 1) * stripWidth : i * stripWidth,
32
26
  },
33
27
  ]}
@@ -104,7 +98,7 @@ export default class Toolbar extends Component {
104
98
  readOnly: false,
105
99
  iconTint: '#71787F',
106
100
  iconSize: 20,
107
- iconGap: 16,
101
+ iconGap: 12,
108
102
  separatorStyle: undefined,
109
103
  };
110
104
 
@@ -372,6 +366,35 @@ export default class Toolbar extends Component {
372
366
  : selected
373
367
  ? that.props.selectedIconTint
374
368
  : that.props.iconTint;
369
+
370
+ let iconContent = null;
371
+ if (icon) {
372
+ if (typeof icon === 'function') {
373
+ iconContent = icon({
374
+ selected,
375
+ disabled,
376
+ tintColor,
377
+ iconSize,
378
+ iconGap,
379
+ width: iconSize,
380
+ height: iconSize,
381
+ color: tintColor,
382
+ fill: tintColor,
383
+ });
384
+ } else {
385
+ iconContent = (
386
+ <Image
387
+ source={icon}
388
+ style={{
389
+ tintColor,
390
+ height: iconSize,
391
+ width: iconSize,
392
+ }}
393
+ />
394
+ );
395
+ }
396
+ }
397
+
375
398
  return (
376
399
  <TouchableOpacity
377
400
  key={action}
@@ -380,30 +403,7 @@ export default class Toolbar extends Component {
380
403
  testID={'button_action'}
381
404
  accessible={true}
382
405
  onPress={() => that._onPress(action)}>
383
- {icon ? (
384
- typeof icon === 'function' ? (
385
- icon({
386
- selected,
387
- disabled,
388
- tintColor,
389
- iconSize,
390
- iconGap,
391
- width: iconSize,
392
- height: iconSize,
393
- color: tintColor,
394
- fill: tintColor,
395
- })
396
- ) : (
397
- <Image
398
- source={icon}
399
- style={{
400
- tintColor,
401
- height: iconSize,
402
- width: iconSize,
403
- }}
404
- />
405
- )
406
- ) : null}
406
+ {iconContent}
407
407
  </TouchableOpacity>
408
408
  );
409
409
  }
@@ -423,6 +423,34 @@ export default class Toolbar extends Component {
423
423
  const currentAlignAction = selectedAlign || actions.alignLeft;
424
424
  const icon = that._getButtonIcon(currentAlignAction);
425
425
 
426
+ let iconContent = null;
427
+ if (icon) {
428
+ if (typeof icon === 'function') {
429
+ iconContent = icon({
430
+ selected,
431
+ disabled,
432
+ tintColor: tintColor,
433
+ iconSize,
434
+ iconGap,
435
+ width: iconSize,
436
+ height: iconSize,
437
+ color: tintColor,
438
+ fill: tintColor,
439
+ });
440
+ } else {
441
+ iconContent = (
442
+ <Image
443
+ source={icon}
444
+ style={{
445
+ tintColor,
446
+ height: iconSize,
447
+ width: iconSize,
448
+ }}
449
+ />
450
+ );
451
+ }
452
+ }
453
+
426
454
  return (
427
455
  <TouchableOpacity
428
456
  key={action}
@@ -431,36 +459,13 @@ export default class Toolbar extends Component {
431
459
  testID={'button_align'}
432
460
  accessible={true}
433
461
  onPress={() => that._onPress(action)}>
434
- {icon ? (
435
- typeof icon === 'function' ? (
436
- icon({
437
- selected,
438
- disabled,
439
- tintColor: tintColor,
440
- iconSize,
441
- iconGap,
442
- width: iconSize,
443
- height: iconSize,
444
- color: tintColor,
445
- fill: tintColor,
446
- })
447
- ) : (
448
- <Image
449
- source={icon}
450
- style={{
451
- tintColor,
452
- height: iconSize,
453
- width: iconSize,
454
- }}
455
- />
456
- )
457
- ) : null}
462
+ {iconContent}
458
463
  </TouchableOpacity>
459
464
  );
460
465
  }
461
466
 
462
467
  _renderSeparator() {
463
- const { style, separatorStyle, iconGap = 16 } = this.props;
468
+ const { style, separatorStyle, iconGap = 12 } = this.props;
464
469
  // Extract separator from style prop (handles both object and array)
465
470
  let separatorFromStyleProp = null;
466
471
  if (style) {
@@ -533,22 +538,6 @@ export default class Toolbar extends Component {
533
538
  }
534
539
  }
535
540
  const vStyle = [styles.barContainer, disabledStyle, containerStyle, disabled && this._getButtonDisabledStyle()];
536
- // Extract backgroundColor from containerStyle (handle array case)
537
- let barBg = TOOLBAR_BG;
538
- if (disabled) {
539
- barBg = '#C9CED7';
540
- } else if (containerStyle) {
541
- if (Array.isArray(containerStyle)) {
542
- for (const styleItem of containerStyle) {
543
- if (styleItem && typeof styleItem === 'object' && styleItem.backgroundColor) {
544
- barBg = styleItem.backgroundColor;
545
- break;
546
- }
547
- }
548
- } else if (typeof containerStyle === 'object' && containerStyle.backgroundColor) {
549
- barBg = containerStyle.backgroundColor;
550
- }
551
- }
552
541
  const showFades = horizontal && !disabled;
553
542
  return (
554
543
  <View style={vStyle}>
@@ -571,12 +560,10 @@ export default class Toolbar extends Component {
571
560
  <FadeOverlay
572
561
  side="left"
573
562
  visible={this.state.showLeftFade}
574
- backgroundColor={barBg}
575
563
  />
576
564
  <FadeOverlay
577
565
  side="right"
578
566
  visible={this.state.showRightFade}
579
- backgroundColor={barBg}
580
567
  />
581
568
  </>
582
569
  )}