Skip to content
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

might be useful for wrapping/truncating #9

Open
github-actions bot opened this issue Jan 3, 2022 · 0 comments
Open

might be useful for wrapping/truncating #9

github-actions bot opened this issue Jan 3, 2022 · 0 comments
Labels

Comments

@github-actions
Copy link

github-actions bot commented Jan 3, 2022

might be useful for wrapping/truncating

if (this.props.numberOfLines !== 1 && !this.props.inline) {

style.flexWrap = "wrap";

}

{inner}

// TODO: might be useful for wrapping/truncating

import React from "react";
import {Text as NativeText} from "react-native";
import Hyperlink from "react-native-hyperlink";
import {TextProps} from "./Common";
import {Unifier} from "./Unifier";

export class Text extends React.Component<TextProps, {}> {
  fontSizes = {
    sm: 12,
    md: 14,
    lg: 16,
  };

  propsToStyle(): any {
    const style: any = {};

    let font:
      | "primaryFont"
      | "primaryBoldFont"
      | "secondaryFont"
      | "secondaryBoldFont"
      | "buttonFont"
      | "accentFont"
      | "accentBoldFont"
      | "titleFont" = "primaryFont";
    if (this.props.font === "primary") {
      if (this.props.weight === "bold") {
        font = "primaryBoldFont";
      } else {
        font = "primaryFont";
      }
    } else if (this.props.font === "secondary") {
      if (this.props.weight === "bold") {
        font = "secondaryBoldFont";
      } else {
        font = "secondaryFont";
      }
    } else if (this.props.font === "button") {
      font = "buttonFont";
    } else if (this.props.font === "title") {
      font = "titleFont";
    } else if (this.props.font === "accent") {
      if (this.props.weight === "bold") {
        font = "accentBoldFont";
      } else {
        font = "accentFont";
      }
    }

    style.fontFamily = Unifier.theme[font];

    style.fontSize = this.fontSizes[this.props.size || "md"];
    if (this.props.align) {
      style.textAlign = this.props.align;
    }
    if (this.props.color) {
      style.color = Unifier.theme[this.props.color];
    } else {
      style.color = Unifier.theme.darkGray;
    }
    // TODO: might be useful for wrapping/truncating
    // if (this.props.numberOfLines !== 1 && !this.props.inline) {
    //   style.flexWrap = "wrap";
    // }
    return style;
  }

  render() {
    let lines = 0;
    if (this.props.numberOfLines) {
      lines = this.props.numberOfLines;
    } else if (this.props.inline) {
      lines = 1;
    }
    const inner = (
      <NativeText numberOfLines={lines} style={this.propsToStyle()}>
        {this.props.children}
      </NativeText>
    );
    if (this.props.skipLinking) {
      return inner;
    } else {
      return (
        // <Hyperlink linkDefault={true} linkStyle={{textDecorationLine: "underline"}}>
        //   {inner}
        // </Hyperlink>
        <Hyperlink linkDefault={true}>{inner}</Hyperlink>
      );
    }
  }
}

115ab15fc6689fdc33364bf06f8c0e727265489a

@github-actions github-actions bot added the todo label Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants