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

(FlatInput): change label fontFamily #4227

Open
fershibli opened this issue Dec 12, 2023 · 2 comments
Open

(FlatInput): change label fontFamily #4227

fershibli opened this issue Dec 12, 2023 · 2 comments
Labels
question Question related to the library, not an issue TextInput

Comments

@fershibli
Copy link

fershibli commented Dec 12, 2023

Description

I've been trying to customize my Input mode="flat", but one thing that I wasn't able to figure out (even reading the source code) was How to change the fontFamily of my Input's label.

I looked over a lot of issues on this repository and I was able to remove the underline from the input and have a different visual for when it is selected/filled.

While looking the original source, I found that I could change it through the project's Theme, but I'm using styled-components/native's ThemeProvider, I'm not sure the cleanest way to accomplish that. It would be better for me to change it directly on the component.

Please, help me to change the label fontFamily. I would be very grateful. Thanks!

Screenshot 2023-12-12 at 19 58 41

Coding

import React from 'react';
import { Styled, StyleSheet } from './styled';

type FlatInputProps = {
  label: string;
  value: string;
  onChangeText: (text: string) => void;
};

const FlatInput: React.FC<FlatInputProps> = ({
  label,
  value,
  onChangeText,
}) => {
  const [isSelected, setIsSelected] = React.useState(false);
  return (
    <Styled.TextInput
      mode="flat"
      label={label}
      value={value}
      onChangeText={(content) => onChangeText(content)}
      onFocus={() => setIsSelected(true)}
      onBlur={() => setIsSelected(false)}
      underlineColor="transparent"
      underlineStyle={StyleSheet.TextInputUnderline}
      theme={StyleSheet.TextInputTheme}
      contentStyle={StyleSheet.TextInputContentStyle}
      bgColor={value.length || isSelected ? 'white' : ''}
    />
  );
};

export default FlatInput;
import styled from 'styled-components/native';
import { TextInput } from 'react-native-paper';
import FONTS from '@src/theme/fonts';

export const Styled = {
  TextInput: styled(TextInput)<{ bgColor?: string }>`
    width: 100%;
    border: 2px solid #f1f2fe;
    background-color: ${(p) => p.bgColor || '#f1f2fe'};
    font-weight: 700;
    margin-bottom: 8px;
  `,
};

export const StyleSheet = {
  TextInputUnderline: {
    display: 'none',
  },
  TextInputTheme: {
    colors: {
      primary: '#2B3267',
      placeholder: '#2B3267',
    },
  },
  TextInputContentStyle: {
    fontFamily: FONTS?.GT_WALSHEIM,
  },
};
@fershibli fershibli added the question Question related to the library, not an issue label Dec 12, 2023
@fershibli
Copy link
Author

I was able to achieve it on iOS by assigning label as a styled Text

<Styled.TextInput
  mode="flat"
  label={<Styled.TextH6>{label}</Styled.TextH6>}
  ... />

But as you can see bellow, it didn't work for Android. Any ideas of how to solve this?

Screenshot 2023-12-13 at 09 40 01
(iOS on the left, Android on the right)

@lukewalczak
Copy link
Member

Hey @fershibli, could you please create an expo snack or sample github repo from your code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question related to the library, not an issue TextInput
Projects
None yet
Development

No branches or pull requests

2 participants