1.1.4 • Published 2 years ago
@mj-studio/react-native-spannable-string v1.1.4
react-native-spannable-string
The simple Text builder for multiple styling in single Text component
How do you make this?
Verbose way 😓
<Text style={{ fontSize: 24 }}>
  Using <Text style={{ fontWeight: 'bold', fontSize: 24 }}>Bold</Text>{' '}
  in Text
</Text>SpannableBuilder way 🔥
SpannableBuilder.getInstance({ fontSize: 24 })
  .append('Using ')
  .appendBold('Bold')
  .append(' in Text')
  .build()Contents 🏆
Install 💠
npm i @mj-studio/react-native-spannable-stringor
yarn add @mj-studio/react-native-spannable-stringUsage 📌
- Import class from package
import SpannableBuilder from '@mj-studio/react-native-spannable-string';- Create SpannableBuilderinstance
Instantiate SpannableBuiler instance with static getInstance function.
getInstance receive TextStyle parameter for base style used by SpannableBuilder
SpannableBuilder.getInstance({ fontSize: 24 })We can also instantate it with Text component with getInstanceWithComponent like this.
SpannableBuilder.getInstanceWithComponent(Text)
// or custom Text component
type Props = { fontFamily: string } & TextProps;
function MyText({fontFamily = 'NotoSansKR-Bold', ...rest}: React.PropsWithChildren<Props>) {
  const { style, children, ...withOutStyle } = rest;
  return (
    <Text style={[style, { fontFamily: fontFamily }]} {...withOutStyle}>
      {children}
    </Text>
  );
}
SpannableBuilder.getInstanceWithComponent(MyText)- Append your texts with spannable free
<View style={{ marginVertical: 64 }}>
  {SpannableBuilder.getInstance({ fontSize: 24 })
    .append('Using ')
    .appendBold('Bold')
    .append(' in Text')
    .build()}
  {SpannableBuilder.getInstance({ fontSize: 24 })
    .append('Using ')
    .appendItalic('Italic')
    .append(' in Text')
    .build()}
  {SpannableBuilder.getInstance({ fontSize: 24 })
    .append('Using ')
    .appendColored('Color', 'red')
    .append(' in Text')
    .build()}
  {SpannableBuilder.getInstance({ fontSize: 24 })
    .append('Using ')
    .appendCustom('Custom Style', {
      textShadowColor: 'blue',
      textShadowRadius: 8,
    })
    .append(' in Text')
    .build()}
</View>
// Sample Title
 SpannableBuilder.getInstance({ fontSize: 44 })
   .appendColored('S', 'red')
   .appendItalic('p')
   .appendCustom('a', {
     fontSize: 30,
     textShadowColor: 'blue',
     textShadowRadius: 12,
   })
   .appendColored('n', 'orange')
   .appendCustom('n', {
     fontSize: 22,
     textDecorationLine: 'underline',
   })
   .appendColored('a', 'skyblue')
   .appendCustom('b', {
     backgroundColor: 'black',
     color: 'white',
     fontSize: 22,
   })
   .appendCustom('l', { fontSize: 18, color: 'red' })
   .appendBold('e ')
   .build(),Change Logs 🔧
- 1.0.0- First Release 🔥
 
- 1.0.1- Add baseStyleparameter ingetInstanceWithComponent
 
- Add 
- 1.0.4- Add config options additionalTextStyle,outerTextStyle
 
- Add config options 
- 1.0.7- Fix additionalTextStyle bugs in appendBold,appendColored,appendItalic
 
- Fix additionalTextStyle bugs in 
- 1.0.8- Enable re-usability of Builder
 
- Enable re-usability of 
- 1.0.9- Add appendBoldWithDelimiter
 
- Add 
- 1.1.1- Ignore if first parameter of appendXXX is not a string
 
- 1.1.3- Add appendCustomWithDelimiter,appendColoredWithDelimiter,appendItalicWithDelimiter,
 
- Add 
feel free your fork or any PR! Thanks
1.1.4
2 years ago
1.1.3
4 years ago
1.1.2
4 years ago
1.1.1
4 years ago
1.1.0
5 years ago
1.1.0-alpha03
5 years ago
1.1.0-alpha01
5 years ago
1.1.0-alpha02
5 years ago
1.0.9
5 years ago
1.0.8
5 years ago
1.0.7
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.4-alpha3
5 years ago
1.0.4
5 years ago
1.0.4-alpha02
5 years ago
1.0.4-alpha
5 years ago
1.0.3
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago