BABIL_PROJECT/BLE
BLE_SCAN 액션 수정 (main/index.js)
ForteQook
2022. 4. 11. 16:57
이 페이지에서는 일단 컴포넌트에 진입하여 scan을 시작하면 stop 할 필요가 없다. 스캔은 계속 진행 하되, 새로고침 버튼을 누르면 BLEList를 초기화하고 다시 스캔한다.
즉, 만약 처음 메인페이지 진입 시 available 했던 디바이스가, 어떤 연유로 더이상 scan 되지 않을 수 도 있지 않은가? 그런 경우 새로고침을 누르면 화면에 반영이 되는 것이다.
ble_actions.js
export const emptyBLEList = () => (dispatch, getState, DeviceManager) => {
DeviceManager.stopDeviceScan()
return dispatch ({
type: EMPTY_BLE,
payload: []
})
}
main/index.js
class MainHome extends Component {
//바이크 리스트를 받아오는 액션을 실행합니다.
componentDidMount() {
this.activateButton()
}
activateButton = async () => {
await this.props.getVehicles()
const uuidList = this.props.VehiclesList.map((item) => item.uuid)
this.props._startScan(uuidList)
}
checkDeviceAvailable = (vehicleName) => {
const bleNameList = this.props.BLEList.map((item) => item.name)
return bleNameList.some((bleName) => bleName == vehicleName)
}
refresh = () => {
this.props.emptyBLEList()
setTimeout(() => this.props._startScan(), 100)
}
...
render () {
...
<View>
<Button
title="새로고침"
onPress={()=>this.refresh()}
/>
</View>
</View>
)
}
}
이 새로고침 버튼을 누르는 방식이 썩 맘에 들지도 않고, 또 최적화도 좀 개판인듯 해서 추후 리팩토링이 필요해 보인다.