1. Dev OS (windows/Mac/Linux) Mac
2. Target OS (iOS/Android/Both) iOS
3. Simulator or real device? (Simulator/Real Device/Both) Real Deivce iPhone 6s
4. react-native V0.54.0, react-native-gesture-handler V1.0.8
here is my code
import React from "react";
import { StyleSheet, Text, View } from "react-native";
import { LargeList } from "react-native-largelist-v2";
import { gestureHandlerRootHOC } from 'react-native-gesture-handler'
import AlphabetPicker from "./AlphabetPicker";
const countries = require('./countryCode.json');
// console.log('data', countries.data);
let lastLetter = '';
class PhoneCodePicker extends React.Component {
state = {
data: countries,
}
onTapLetter = (letter) => {
if (lastLetter === letter) return;
lastLetter = letter;
const letterIndex = this.state.data.findIndex(country => country.key.toLowerCase() === letter.toLowerCase());
console.log('index', letterIndex);
if (letterIndex > -1) {
this.listRef.scrollToIndexPath({section: letterIndex, row: 0}, false)
}
// this.listRef.scrollToIndexPath({animated: true, itemIndex: index})
}
render() {
return (
<View style={styles.container}>
<LargeList
style={styles.container}
data={this.state.data}
heightForSection={() => 50}
renderSection={this._renderSection}
heightForIndexPath={() => 50}
renderIndexPath={this._renderIndexPath}
ref={list => this.listRef = list}
/>
<View style={styles.sidebar}>
<AlphabetPicker onTapLetter={this.onTapLetter} />
</View>
</View>
);
}
_renderSection = (section) => {
console.log('section header', section)
const country = this.state.data[section];
return (
<View style={styles.section}>
<Text>
{country.key}
</Text>
</View>
);
};
_renderIndexPath = ({ section, row }) => {
console.log('section body', section, row);
const country = this.state.data[section].items[row];
return (
<View style={styles.row}>
<Text>
{country.countryName} +{country.phoneCode}
</Text>
<View style={styles.line} />
</View>
);
};
}
const styles = StyleSheet.create({
container: {
flex: 1
},
section: {
flex: 1,
backgroundColor: "gray",
justifyContent: "center",
alignItems: "center"
},
row: {
flex: 1,
justifyContent: "center",
alignItems: "center"
},
line: {
position: "absolute",
left: 0,
right: 0,
bottom: 0,
height: 1,
backgroundColor: "#EEE"
},
sidebar: {
position: 'absolute',
right: 0,
width: 30,
}
});
export default gestureHandlerRootHOC(PhoneCodePicker)
and some part of countriesJSON:
[
{
"items": [
{
"countryName": "安道尔",
"countryPinyin": "an dao er",
"phoneCode": "376",
"countryCode": "AD"
},
{
"countryName": "阿拉伯联合酋长国",
"countryPinyin": "a la bo lian he qiu zhang guo",
"phoneCode": "971",
"countryCode": "AE"
},
{
"countryName": "阿富汗",
"countryPinyin": "a fu han",
"phoneCode": "93",
"countryCode": "AF"
},
{
"countryName": "安提瓜和巴布达",
"countryPinyin": "an ti gua he ba bu da",
"phoneCode": "1",
"countryCode": "AG"
},
{
"countryName": "安圭拉",
"countryPinyin": "an gui la",
"phoneCode": "1",
"countryCode": "AI"
},
{
"countryName": "阿尔巴尼亚",
"countryPinyin": "a er ba ni ya",
"phoneCode": "355",
"countryCode": "AL"
},
{
"countryName": "安哥拉",
"countryPinyin": "an ge la",
"phoneCode": "244",
"countryCode": "AO"
},
{
"countryName": "阿根廷",
"countryPinyin": "a gen ting",
"phoneCode": "54",
"countryCode": "AR"
},
{
"countryName": "奥地利",
"countryPinyin": "ao de li",
"phoneCode": "43",
"countryCode": "AT"
},
{
"countryName": "澳大利亚",
"countryPinyin": "ao da li ya",
"phoneCode": "61",
"countryCode": "AU"
},
{
"countryName": "阿鲁巴",
"countryPinyin": "a lu ba",
"phoneCode": "297",
"countryCode": "AW"
},
{
"countryName": "阿塞拜疆",
"countryPinyin": "a sai bai jiang",
"phoneCode": "994",
"countryCode": "AZ"
},
{
"countryName": "阿尔及利亚",
"countryPinyin": "a er ji li ya",
"phoneCode": "213",
"countryCode": "DZ"
},
{
"countryName": "爱沙尼亚",
"countryPinyin": "ai sha ni ya",
"phoneCode": "372",
"countryCode": "EE"
},
{
"countryName": "埃及",
"countryPinyin": "ai ji",
"phoneCode": "20",
"countryCode": "EG"
},
{
"countryName": "埃塞俄比亚",
"countryPinyin": "ai sai e bi ya",
"phoneCode": "251",
"countryCode": "ET"
},
{
"countryName": "爱尔兰",
"countryPinyin": "ai er lan",
"phoneCode": "353",
"countryCode": "IE"
},
{
"countryName": "阿曼",
"countryPinyin": "a man",
"phoneCode": "968",
"countryCode": "OM"
}
],
"key": "A"
},
{
"items": [
{
"countryName": "波斯尼亚和黑塞哥维那",
"countryPinyin": "bo si ni ya he hei sai ge wei na",
"phoneCode": "387",
"countryCode": "BA"
},
{
"countryName": "巴巴多斯",
"countryPinyin": "ba ba duo si",
"phoneCode": "1",
"countryCode": "BB"
},
{
"countryName": "比利时",
"countryPinyin": "bi li shi",
"phoneCode": "32",
"countryCode": "BE"
},
{
"countryName": "布基纳法索",
"countryPinyin": "bu ji na fa suo",
"phoneCode": "226",
"countryCode": "BF"
},
{
"countryName": "保加利亚",
"countryPinyin": "bao jia li ya",
"phoneCode": "359",
"countryCode": "BG"
},
{
"countryName": "巴林",
"countryPinyin": "ba lin",
"phoneCode": "973",
"countryCode": "BH"
},
{
"countryName": "布隆迪",
"countryPinyin": "bu long di",
"phoneCode": "257",
"countryCode": "BI"
},
{
"countryName": "贝宁",
"countryPinyin": "bei ning",
"phoneCode": "229",
"countryCode": "BJ"
},
{
"countryName": "百慕大",
"countryPinyin": "bai mu da",
"phoneCode": "1",
"countryCode": "BM"
},
{
"countryName": "玻利维亚",
"countryPinyin": "bo li wei ya",
"phoneCode": "591",
"countryCode": "BO"
},
{
"countryName": "巴西",
"countryPinyin": "ba xi",
"phoneCode": "55",
"countryCode": "BR"
},
{
"countryName": "巴哈马",
"countryPinyin": "ba ha ma",
"phoneCode": "1",
"countryCode": "BS"
},
{
"countryName": "不丹",
"countryPinyin": "bu dan",
"phoneCode": "975",
"countryCode": "BT"
},
{
"countryName": "博茨瓦纳",
"countryPinyin": "bo ci wa na",
"phoneCode": "267",
"countryCode": "BW"
},
{
"countryName": "白俄罗斯",
"countryPinyin": "bai e luo si",
"phoneCode": "375",
"countryCode": "BY"
},
{
"countryName": "伯利兹",
"countryPinyin": "bo li zi",
"phoneCode": "501",
"countryCode": "BZ"
},
{
"countryName": "冰岛",
"countryPinyin": "bing dao",
"phoneCode": "354",
"countryCode": "IS"
},
{
"countryName": "北马里亚纳群岛",
"countryPinyin": "bei ma li ya na qun dao",
"phoneCode": "1",
"countryCode": "MP"
},
{
"countryName": "巴拿马",
"countryPinyin": "ba na ma",
"phoneCode": "507",
"countryCode": "PA"
},
{
"countryName": "巴布亚新几内亚",
"countryPinyin": "ba bu ya xin ji nei ya",
"phoneCode": "675",
"countryCode": "PG"
},
{
"countryName": "巴基斯坦",
"countryPinyin": "ba ji si tan",
"phoneCode": "92",
"countryCode": "PK"
},
{
"countryName": "波兰",
"countryPinyin": "bo lan",
"phoneCode": "48",
"countryCode": "PL"
},
{
"countryName": "波多黎各",
"countryPinyin": "bo duo li ge",
"phoneCode": "1",
"countryCode": "PR"
},
{
"countryName": "巴勒斯坦领土",
"countryPinyin": "ba lei si tan ling tu",
"phoneCode": "970",
"countryCode": "PS"
},
{
"countryName": "巴拉圭",
"countryPinyin": "ba la gui",
"phoneCode": "595",
"countryCode": "PY"
}
],
"key": "B"
}
]
Same as issue 188,but V2 has no 'numberOfSectionPoolSize' property.