[Android TV] Cannot move focus at some component
Nobody has claimed this yet.
Assessment
This issue has not been assessed yet.
Description
Hi, can anyone explain this weird Behaviour to me ? I have 3 TVFocusGuideView for those 3 lines of items, first contain a text input, second contains some Pressable display some abc text, and the last contains a virtualized list render a pressable with number.
- If i not show the first TVFocusGuideView which contain the text input, i can navigate between the text row and the number row fine.
- If i show the first TVFocusGuideView which contain the text input, when at the text input, if i press D-pad Down it jump to the Number Row, from number row, i cant move Up to the Text Row from the button [0], can move up from the button [1], and when at Text Row i cant move up to the text input.
for the 2. , if i add some margin to first pressable ( e.g: marginLeft:100, it can move the focus up )
Is there anyway to debug the focus behaviour better ?
Here is the code , i test on android tv emulator
import { useRef, useState } from "react";
import { Pressable, StyleSheet, TextInput, TVFocusGuideView, View, VirtualizedList,Text} from "react-native";
const TestItemZ=({idx}:any)=>{
var magicMargin=0;//depend,sometime 50 work
return <Pressable key={"item-"+idx} style={({focused})=>[
{marginLeft:magicMargin,width:200,height:100,justifyContent:'center',
alignItems:'center',backgroundColor:'green',marginRight:5},
focused&&{backgroundColor:'yellow'}]}>
<Text>{idx.item==0?'cant move up':idx.item.toString()}</Text>
</Pressable>
}
const TestSectionHeader=()=>{
const firstBTN = useRef<View>(null);
return <TVFocusGuideView
destinations={[firstBTN.current]}
key={'test-bar'}
autoFocus trapFocusLeft trapFocusRight
style={[{width:'100%', height:50,display:'flex',flexDirection:'row',alignItems:'center',
marginBottom:10,backgroundColor:'#fff'}]}>
{
['abc','def','ghi','jkl','mno','pqr','stu'].map((txt)=>{
return <Pressable key={"btn-"+txt} style={({focused})=>[{width:100,height:50},focused&&{backgroundColor:'yellow'}]}>
{({focused})=>
<Text style={[
{color:'#fff',textAlign:'center',backgroundColor:'blue',height:50,lineHeight:50},
focused&&{color:'red'}]}>
{txt}
</Text>
}</Pressable>
})
}
</TVFocusGuideView>
};
const TestSection=()=> {
const firstRef=useRef(null);
return <View
key={'view-container'}
style={[styles.sectionContainer]}>
<TestSectionHeader/>
<TVFocusGuideView >{/* without this wrapper it still not work */}
<VirtualizedList
horizontal={true}
overScrollMode={"never"}
getItemCount={()=>10}
data={[1,2,3,4,5,6,7,8,9,10]}
key={'test-vlist'}
keyExtractor={(_,idx:number)=>{
return 'vlist-'+idx.toString();
}}
getItem={(_:any,idx:number)=>{return idx}}
style={[{backgroundColor:'pink'}]}
renderItem={(idx:any)=>{
console.log(idx);
return <TestItemZ idx={idx}/>
}}>
</VirtualizedList>
</TVFocusGuideView>
</View>;
};
export default function IndexPage(){
const SearchBox=useRef<TextInput>(null);
const [SearchText,setSearchText] = useState("");
var searchIDX=0;
return(<View>
{/*<SafeAreaView style={styles.container}>
<GestureHandlerRootView style={{height:700,width:'100%'}} >*/}
{/*<StatusBar style="light" hidden={true}/>*/}
<View style={styles.searchPageContainer}>
<TVFocusGuideView key="first-tv-guide" style={[styles.searchBoxBackground,{backgroundColor:'dodgerblue'}]}>
<TextInput
style={styles.searchBoxInput}
placeholderTextColor={'rgba(142, 148, 162, 1)'}
underlineColorAndroid='rgba(0,0,0,0)'
ref={SearchBox}
placeholder={"This is TextInput"}
autoFocus={true}
value={SearchText}
onChangeText={(text) => {
setSearchText(text);
}}
onSubmitEditing={()=>{
console.log(86,"submit editing ",SearchText);
}}
/>
</TVFocusGuideView>
<View key="search-page-sr" style={[styles.searchResult]}>
<TestSection/>
</View>
</View>
{/* </GestureHandlerRootView>
</SafeAreaView>
*/}
</View>
);
}
const styles=StyleSheet.create({
container:{
width:'100%',
height:600,
overflow:'scroll',
paddingTop:0,
justifyContent:'center',
display:'flex',
flexDirection:'row',
},
sectionContainer:{
width:'100%',
height:'auto'
},
searchPageContainer:{
backgroundColor:'gray',
height:100,
width:'100%',
display:'flex',
flexDirection:'column'
},
searchBoxBackground:{
width:'100%',
height:50,
borderRadius:4,
flexDirection:'row',
justifyContent:'space-between',
alignItems:'center',
marginBottom:5,
},
searchBoxInput:{
width:'100%',
height:'100%',
color:'rgba(142, 148, 162, 1)',
borderWidth:0,
zIndex:9999,
},
searchResult:{
width:'100%',
height:200,
zIndex:10,
backgroundColor:'purple'
},
});
- Dominant language
- C++
- Stars
- 1.4k
- Forks
- 194
- Avg merge
- 1d 59m
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from react-native-tvos/react-native-tvos
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
-
react-native-tvos/react-native-tvos#1087 · 1 comment · 1 reaction · 1 assignee ·
-
bug regression
react-native-tvos/react-native-tvos#1058 · 1 reaction · 1 assignee ·
-
bug core issue
react-native-tvos/react-native-tvos#1052 · 1 comment · 1 assignee ·
All issues in react-native-tvos/react-native-tvos
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
Sensor initialization takes very long when `--initial-sim-time` is set to current UNIX timestamp Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gazebosim/gz-sensors#662 · 1 comment ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
LadybirdBrowser/ladybird#12123 ·