2017-07-14 37 views
2

我想在我的文本週圍放一個邊框。反應vr邊界不起作用

<View style={{ borderRadius: 1, borderWidth: 1, borderColor:'#FF0000',}}> 
      <Text style={{ 
       fontSize: 0.8, 
       fontWeight: '400', 
       layoutOrigin: [0.5, 0.5], 
       paddingLeft: 0.2, 
       paddingRight: 0.2, 
       textAlign: 'center', 
       textAlignVertical: 'center', 
       transform: [{translate: [0, 0, -3]}], 
      }}> 
       hello 
      </Text> 
      </View> 

如果我將borderWidth作爲1,我會看到hello但看不到邊框。如果我將borderWidth更改爲10,我什麼都看不到。我如何在hello文本中添加邊框?

+0

你可以請創建一個jsFiddle嗎? –

+0

我不知道如何把它放在jsFiddle,但繼承人的git鏈接https://github.com/lunzhang/react-vr-tetris。您只需將src/index.vr.js中的代碼替換爲我發佈的代碼 –

+0

不幸的是,無法在任何流行的操場(codepen,jsbin等)中嵌入React VR代碼,有人應該對開發人員進行bug在Github上關於這個:) – Valentin

回答

1

邊框確實在工作,但是您的視圖默認位於相機視圖所在場景的中心。你真正想要做的就是在你的根視圖上設置layoutOrigin,並在翻譯中設置所有組件在那裏正確渲染。

這應做到:

<View style={{ 
    borderRadius: 1, 
    borderWidth: 1, 
    borderColor:'#FF0000', 
    transform: [{translate: [0, 0, -3]}], 
    layoutOrigin: [0.5, 0.5], 
}}> 
    <Text style={{ 
     fontSize: 0.8, 
     fontWeight: '400', 
     paddingLeft: 0.2, 
     paddingRight: 0.2, 
     textAlign: 'center', 
     textAlignVertical: 'center', 
    }}>hello</Text> 
</View> 

這應該正確地顯示在你的文字邊框,雖然你會發現邊框的寬度過大,因爲單位不意味着像素,但是米3D世界。