Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PixelDrawingView: Posible solución para refrescar el borrado #10

Open
cHuMaRi opened this issue May 24, 2022 · 0 comments
Open

PixelDrawingView: Posible solución para refrescar el borrado #10

cHuMaRi opened this issue May 24, 2022 · 0 comments

Comments

@cHuMaRi
Copy link

cHuMaRi commented May 24, 2022

No se si será la mejor solución, pero se podría hacer lo siguiente...

En PixelDrawingView declaramos una variable binding para pasarle el array de pixelArts

@Binding public var parentPixelArts: [PixelArt]

Modificamos el init de PixelDrawingView añadiendo el nuevo parámetro parentPixelArts y lo asignamos a la variable Binding:

/// Must be public to allow creating instances out of this package
    public init(pixelArt: Binding<PixelArt>, parentPixelArts: Binding<[PixelArt]>) {
        self._pixelArt = pixelArt
        self._draftPixelArt = State(initialValue: pixelArt.wrappedValue)
        self._parentPixelArts = parentPixelArts
    }

Modificamos el body de PixelDrawingView con lo siguiente:

public var body: some View {
        if !parentPixelArts.contains(where: {$0.id == self.pixelArt.id || $0.name == self.pixelArt.name}) {
            Text("PixelArt has been deleted!")
        }else{

He puesto una doble condición porque el PixelArt.from cambia el "id"... habría que tener una clave id fija que no cambiara.
Asumo que el nombre es clave.

Por último solo faltaría pasar el array de pixelArts en PixelArtListView:

struct PixelArtListView: View {
    
    @State var pixelArts: [PixelArt]
 
    var body: some View {
        NavigationView{
            List($pixelArts) { pixelArt in
                NavigationLink(destination: PixelDrawingView(pixelArt: pixelArt, parentPixelArts: $pixelArts)){
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant