Last active
December 17, 2021 06:27
-
-
Save Clancey/c7fdfb1590017d42115bc5dd304ea2c9 to your computer and use it in GitHub Desktop.
Comet ImagePicker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainPage : View | |
{ | |
readonly State<int> ImageCount = new State<int>(); | |
readonly State<List<(string Path, string Name)>> images = new List<(string Path, string Name)>(); | |
Task<FileResult> currentPickerTask; | |
[Body] | |
View body() | |
=> new VStack { | |
new HStack(Comet.VerticalAlignment.Center){ | |
new Button("From Photos", async ()=>{ | |
var file = await (!(currentPickerTask?.IsCompleted ?? true) ? currentPickerTask : (currentPickerTask = MediaPicker.PickPhotoAsync())); | |
AddImage(file); | |
}), | |
!MediaPicker.IsCaptureSupported ? new Text("Camera Not Supported") : new Button("Take From Camera", async ()=>{ | |
var file = await (!(currentPickerTask?.IsCompleted ?? true) ? currentPickerTask : (currentPickerTask = MediaPicker.CapturePhotoAsync())); | |
AddImage(file); | |
}), | |
}, | |
new ScrollView(Orientation.Horizontal){ | |
new HStack{ | |
Enumerable.Range(0,ImageCount.Value).Select(x=> new VStack{ | |
new Image(()=> images.Value[x].Path).Frame(width:100,height:100), | |
new Button("Remove", ()=>{ | |
images.Value.RemoveAt(x); | |
ImageCount.Value--; | |
}) | |
}), | |
}.Frame(height:110).Background(Colors.White) | |
}.Frame(height:200), | |
new Text(uploadStatus), | |
}; | |
void AddImage(FileResult file) | |
{ | |
if (file == null) | |
return; | |
images.Value.Add((file.FullPath, file.FileName)); | |
ImageCount.Value = images.Value.Count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment