Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

React Native : Conditional Views

$
0
0

I want to make it so that depending on my result(the number of elements of my data), I could add a certain number of row to my code.For exemple if this number is 0=>1row, 1=>1row, 2=>2row,3=>2row, 4=>3row, ...I did try but the result is always on 1 line :

              let count = 0;              let reste = 0;              let total = 1;              let same = 0;...//I'm doing a map of my data here so this code is used as many time as there is of elements //in my data                    if (total !== same) {                      return (<View style={{ width: "40%", marginLeft: 70 }}><Text                            style={{                              fontSize: 18,                              fontWeight: "600",                              marginTop: 25,                              width: "50%",                            }}>                            {count++}                            {(reste = count % 2)}                            {(total = (count + reste) / 2)}                            {letter.data[index]}                            {"\n"}</Text><Text style={{ marginTop: 50, width: "50%" }}>                            {letter.description[index]}                            {"\n"}</Text></View>                      );                    } else {                      return (<View style={{ flexDirection: "column" }}><View style={{ width: "40%", marginLeft: 70 }}><Text                              style={{                                fontSize: 18,                                fontWeight: "600",                                marginTop: 25,                                width: "50%",                              }}>                              {count++}                              {(reste = count % 2)}                              {(total = (count + reste) / 2)}                              {letter.data[index]}                              {"\n"}</Text><Text style={{ marginTop: 50, width: "50%" }}>                              {letter.description[index]}                              {"\n"}</Text></View></View>                      );                    }

Is there any solution ? I didn't find anything.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>