Skip to content

Add selectable text component #935

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
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ import PinInputExample from "./PinInputExample";
import KeyboardAvoidingViewExample from "./KeyboardAvoidingViewExample";
import ThemeExample from "./ThemeExample";
import LoadingIndicatorExample from "./LoadingIndicatorExample";
import SelectableTextExample from "./SelectableTextExample";

const ROUTES = {
SelectableText: SelectableTextExample,
LoadingIndicator: LoadingIndicatorExample,
Theme: ThemeExample,
AudioPlayer: AudioPlayerExample,
Expand Down
24 changes: 24 additions & 0 deletions example/src/SelectableTextExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from "react";
import { SelectableText, withTheme } from "@draftbit/ui";
import Section, { Container } from "./Section";

const SelectableTextExample: React.FC = () => {
return (
<Container style={{}}>
<Section style={{}} title="Default">
<SelectableText text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." />
</Section>
<Section style={{}} title="With styling">
<SelectableText
text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
style={{
fontSize: 30,
fontWeight: "bold",
}}
/>
</Section>
</Container>
);
};

export default withTheme(SelectableTextExample);
50 changes: 50 additions & 0 deletions packages/core/src/components/SelectableText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from "react";
import {
Platform,
TextInput,
Text,
TextStyle,
I18nManager,
StyleSheet,
TextInputProps,
TextProps,
StyleProp,
} from "react-native";

type Props = {
style?: StyleProp<TextStyle>;
text?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the text be passed in as children? Similar to how the normal Text component works

} & (TextInputProps | TextProps);

const SelectableText: React.FC<Props> = ({ style, text, ...rest }) => {
const writingDirection: "auto" | "ltr" | "rtl" = I18nManager.isRTL
? "rtl"
: "ltr";

const baseStyle = [styles.baseText, { writingDirection }, style];
if (Platform.OS === "ios") {
return (
<TextInput
{...rest}
value={text}
editable={false}
scrollEnabled={false}
multiline
style={baseStyle}
/>
);
}
return (
<Text {...rest} selectable style={baseStyle}>
{text}
</Text>
);
};

const styles = StyleSheet.create({
baseText: {
textAlign: "left",
},
});

export default SelectableText;
1 change: 1 addition & 0 deletions packages/core/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export { default as SimpleStyleScrollView } from "./components/SimpleStyleScroll
export { default as SimpleStyleSectionList } from "./components/SimpleStyleScrollables/SimpleStyleSectionList";
export { default as SimpleStyleSwipeableList } from "./components/SimpleStyleScrollables/SimpleStyleSwipeableList";
export { default as LoadingIndicator } from "./components/LoadingIndicator";
export { default as SelectableText } from "./components/SelectableText";

/* Deprecated: Fix or Delete! */
export { default as AccordionItem } from "./deprecated-components/AccordionItem";
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export {
SimpleStyleSectionList,
SimpleStyleSwipeableList,
LoadingIndicator,
SelectableText,
} from "@draftbit/core";

export {
Expand Down
Loading