local variables in GeometryReader

(deprecated)

็พๅœจๅœจ ViewBuilder ่ฃก้ขๅทฒ็ถ“ๅฏไปฅๅพˆๆ–นไพฟๅœฐ่จญๅฎšๅ€ๅŸŸ่ฎŠๆ•ธไบ†ใ€‚

ไธ‹้ข้€™ๅ€‹็ฏ„ไพ‹็คบ็ฏ„ๅฆ‚ไฝ•ๅœจ GemometryReader ๅ…งๅฏไปฅๆ–นไพฟไฝฟ็”จๅ€ๅŸŸ่ฎŠๆ•ธ๏ผš

struct SomeView: View {
    
    // 1. ๅ…ˆๅšไธ€ๅ€‹ๅฏไปฅๆŽฅๆ”ถ GeometryProxy ็„ถๅพŒๅ›žๅ‚ณ View ็š„ๅ‡ฝๆ•ธ
    func makeView(with geometry: GeometryProxy) -> some View {
        // 2. ๅœจ้€™่ฃกๅฏไปฅไธ€ไบ›่จˆ็ฎ—
        //    ...
        // 3. ็„ถๅพŒๅ†ๅ‚ณๅ›žไธ€ๅ€‹ View ็ตฆ GeometryReader ็”จ
        return Color.clear
    }
    
    var body: some View {
        GeometryReader { geo in
            // 4. ไฝฟ็”จไธŠ้ข็š„ `makeView(with:)` 
            self.makeView(with: geo)
        }
    }
}

Last updated