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

Icons not working (showing ? instead) #2832

Closed
grean opened this issue Jul 30, 2019 · 26 comments
Closed

Icons not working (showing ? instead) #2832

grean opened this issue Jul 30, 2019 · 26 comments

Comments

@grean
Copy link

grean commented Jul 30, 2019

Hello,

With those versions on windows 10 64bits:
"native-base": "2.12.2",
"react-native": "0.60.4",
"react-native-vector-icons": "6.6.0" -> (i know that this is not the dev-depedencie 6.1.0 but it works with NB 2.12.1)

Icons are displayed with '?' instead of the good one (fontAwesome for my case)
If i downgrade to "native-base": "2.12.1" it works well..

What about NativeBase working with RN 0.60.x and the fact that linking process is no longer needed with RN 0.60.x ?

I've replaced my custom theme with the native-base one (using node node_modules/native-base/ejectTheme.js) without changing a line but it does'nt solve my isssue.

@grean
Copy link
Author

grean commented Jul 30, 2019

I finally get my icon but why do i have to add an option (type="FontAwesome") in the native base Icon component whereas it was not needed/required in NB 2.12.1
I don't see that in changelog too of the 2.12.2 version.. maybe default behavior is broken and always fallback to ionicons when there is no type prop in NB Icon component.

@stevesweets
Copy link

Similar issue, but ionicons not loading for me.

@stevesweets
Copy link

Resolved with this comment: #2806 (comment)

@grean
Copy link
Author

grean commented Jul 31, 2019

@stevesweets i'm not sure it's the same issue.
For me fonts are presents and loaded but NativeBase don't use the one i've specified in the theme iconFontFamily variable. Thus i have '?' instead because the icon's name that i used are not present in the font that is loaded. When there is are Square with a cross inside, it means that the font was not found at all i believe.
I repeat that, now, it's working for me because i'va added the 'type' prop in icon component that i had not to do before 2.12.2 O_o

@danieloprado
Copy link
Contributor

Something after this merge #2804 broken the default behaviour

@PlabanJr
Copy link
Contributor

PlabanJr commented Aug 7, 2019

Something after this merge #2804 broken the default behaviour

Can you please share some more details about the broken behaviour, preferably screenshots and snacks to reproduce.

@PlabanJr
Copy link
Contributor

PlabanJr commented Aug 7, 2019

Please refer to this. Hope this solves the issue.

@grean
Copy link
Author

grean commented Aug 7, 2019

This is not a 'linking' problem.
The problem is that the variable that store the icon's type in your ejected theme file for the whole project in no more taken into account.

From my theme file 'platform.js'

 // Icon
    iconFamily: 'FontAwesome',

Now, i have to add the prop 'type="FontAwesome"' to each component in order to make it work. Before this was not the case. If you don't provide the 'type' prop to your Icon's component they try to display icon's from a default font (ionicons i think) So icons appear with a '?' instead and not with a 'cross' like this X. If i try with a name that exist in ionicons font it's displaying good.

@nismaxim82
Copy link

This is not a 'linking' problem.
The problem is that the variable that store the icon's type in your ejected theme file for the whole project in no more taken into account.

From my theme file 'platform.js'

 // Icon
    iconFamily: 'FontAwesome',

Now, i have to add the prop 'type="FontAwesome"' to each component in order to make it work. Before this was not the case. If you don't provide the 'type' prop to your Icon's component they try to display icon's from a default font (ionicons i think) So icons appear with a '?' instead and not with a 'cross' like this X. If i try with a name that exist in ionicons font it's displaying good.

It's a bug. Here is i'm write a comment on that.
805577d#commitcomment-34672919

You can fix it by your self until the next version fixes this:

  1. Open file node_modules\native-base\dist\src\basic\IconNB.js and remove all text code.
  2. Copy to the file code from the node_modules\native-base\src\basic\IconNB.js
  3. Add lifecycle function code:
    componentWillMount() { this.setIcon(this.props.type); }
  4. Run your app and check it.

P.S. You can add this function to the file in the second step and run npm command compile to recompile library.

@danieloprado danieloprado mentioned this issue Aug 13, 2019
6 tasks
@r0b0t3d
Copy link

r0b0t3d commented Aug 26, 2019

version 2.13.5, componentDidUpdate method is using wrong param. #2806 (comment)

In IconNB.js

componentDidUpdate(nextProps) {
    if (nextProps.type && this.props.type !== nextProps.type) {
      this.setIcon(nextProps.type);
    }
  }

should be

componentDidUpdate(prevProps) {
    if (prevProps.type && this.props.type !== prevProps.type) {
      this.setIcon(this.props.type);
    }
  }

For now, I have to back to 2.13.4

@sankhadeeproy007
Copy link
Contributor

Fixed in 2.13.8

@craftzdog
Copy link

craftzdog commented Sep 13, 2019

Seems like componentWillMount() { this.setIcon(this.props.type); } is still needed in 2.13.8.
Maybe that's because this.context is always undefined in constructor method, so theme is not loaded properly.

craftzdog added a commit to craftzdog/NativeBase that referenced this issue Sep 13, 2019
`this.context` is always `undefined` in `constructor` method. Refer `context` argument instead.

fix GeekyAnts#2832
@grean
Copy link
Author

grean commented Sep 13, 2019

I've tested the lastest version (2.13.8) and i've removed the 'type' prop in an 'Icon' component to test if it's always required and it shows me a '?' instead of the correct icon. So, i think that the problem still exist in this version :(

@jpolo
Copy link

jpolo commented Sep 16, 2019

I confirm, it is back in 2.13.8

@rodriguezmanu
Copy link

+1

@MarcosOmineJr
Copy link

Mine is not even showing the '?', it just doesn't load:

NativeBase-Icons

The icon on the left is a test to see if <Icon /> works, and apparently, it doesn't.

The Icons code:

<Container style={styles.checkBoxContainer}>
    <Icon type='FontAwesome' name='check' style={{color: palette.default.mainColor}} /> //Test Icon
    <CheckBox
        color={palette.default.mainColor}
        style={styles.check}
        checked={this.state.persistConnection}
        onPress={()=>{
            let s = this.state;
            s.persistConnection = s.persistConnection?false:true;
            this.setState(s);
        }}
    />

    <Text style={styles.checkLabel}>Manter-se conectado</Text>
</Container>

My dependencies in package.json:

{
"@react-native-community/async-storage": "^1.6.2",
    "native-base": "^2.13.8",
    "react": "16.8.3",
    "react-native": "0.59.3",
    "react-native-gesture-handler": "^1.4.1",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-reanimated": "^1.3.0",
    "react-native-screens": "1.0.0-alpha.23",
    "react-native-splash-screen": "3.0.6",
    "react-navigation": "^4.0.10",
    "react-navigation-stack": "^1.9.0"
}

am I doing something wrong?

@bullantt
Copy link

bullantt commented Feb 4, 2020

Fixed in 2.13.8

This still not fixed thank you nismaxim82 i had been looking everywhere for a solution after upgrading this worked after adding componentWillMount() { this.setIcon(this.props.type); }

"dependencies": { "native-base": "^2.13.8", "prop-types": "^15.7.2", "react": "^16.12.0", "react-art": "^16.3.2", "react-dom": "^16.3.2", "react-native": "^0.61.5", "react-native-code-push": "^6.0.0", "react-native-device-info": "^5.4.3", },

@jknight12882
Copy link

also confirming not fixed in 2.13.8

@kharbandaashu
Copy link

also confirming not fixed in 2.13.8

This one Worked for me for following configuration.

"native-base": "^2.13.8",
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-vector-icons": "^6.6.0"

@mufaddalhamidofficial
Copy link

what about workin expo

@bearkfear
Copy link

bearkfear commented Mar 18, 2020

I fix this problem in my project importing the fontFamiliy that i want: https://expo.github.io/vector-icons/

Follow the code:

const Index = () => {
  const [ready, setReady] = useState(false);
  if (!ready)
    return (
      <AppLoading
        startAsync={async () =>
          await Font.loadAsync({
            Ionicons: require("native-base/Fonts/Ionicons.ttf")
          })
        }
        onFinish={() => setReady(true)}
      ></AppLoading>
    );
  return (
    <StyleProvider style={getTheme(platform)}>
      <NavigationContainer>
        <Routes></Routes>
      </NavigationContainer>
    </StyleProvider>
  );
};

in the folder Fonts on the native-base you find more:
image

My dependencies:

  • "@expo/vector-icons": "^10.0.6",
  • "@react-native-community/masked-view": "0.1.5",
  • "@react-navigation/bottom-tabs": "^5.1.1",
  • "@react-navigation/native": "^5.0.9",
  • "@react-navigation/stack": "^5.1.1",
  • "expo": "^36.0.2",
  • "expo-font": "^8.0.0",
  • "native-base": "^2.13.12",
  • "react": "16.9.0",
  • "react-dom": "16.9.0",
  • "react-native": "https://github.com/expo/react-native/archive/sdk-36.0.1.tar.gz",
  • "react-native-gesture-handler": "~1.5.0",
  • "react-native-reanimated": "~1.4.0",
  • "react-native-safe-area-context": "0.6.0",
  • "react-native-screens": "2.0.0-alpha.12",
  • "react-native-web": "^0.11.7"

@Pat-Gekoski
Copy link

I ran yarn add @expo/vector-icons and rebuilt the project. Fixed it for me

@kenken023
Copy link

Issue still persists on "native-base": "2.13.14"
But for me, the play displays a wrong icon and others are question mark for Ionicons

Screenshot 2020-09-26 at 6 19 04 PM

@DGeoWils
Copy link

DGeoWils commented Oct 8, 2020

I had the same issue. I don't use expo.

"react-native": "0.60.4", "native-base": "^2.13.14",

ran yarn add react-native-vector-icons.

I then had to remove the fonts from the "Copy Bundle Resources" phase in xcode in order to build for ios.

@Mazhar-khan
Copy link

I have same issue icon not working.
Back button is not working.

@badalsaibo
Copy link

If you're using the latest react-native-vector-icons, follow the steps mentioned in the docs for Android setup.

Edit android/app/build.gradle (NOT android/build.gradle) and add:

apply from: file("../../node_modules/react-native-vector-icons/fonts.gradle")

https://github.com/oblador/react-native-vector-icons?tab=readme-ov-file#android-setup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.