I am Working on an app with requirement where we need to create a dynamic image gallery which refreshes after few minutes.When refresh happens three things should happen without reloading the page
1) Obsolete images should be removed
2) New Images should be added
3) Non Obsolete images should stay (not reload)
4) Images should be stacked next to each other as it will be mostly used on tablet
I was looking at Boxlayout or FlowLayout and I can add the image but I am not sure how to delete it dynamically .I was able to set UUID for the image component but was not able to get component based on UUID to remove it . How can I get component based on its UUID added to the form ?
Is this the correct approach ? or there is already build in component that does that .
I saw this
How to add dynamic data in the renderer created using UI builder?
But I also read using List is discouraged
https://www.codenameone.com/javadoc/com/codename1/ui/list/package-summary.html
This is actually pretty simple to do with a BoxLayout.Y_AXIS Container. When you create an image component to add to the box layout do this:
myImageComponent.putClientProperty("imageId", imageId);
Then when you have the callback to refresh the list just do something like this:
for(Component cmp : parentContainer) {
String id = (String)myImageComponent.getClientProperty("imageId");
if(!existsInNewList(id)) {
cmp.remove();
}
}
When you are done updating the container just call animateLayout(200) or revalidate() to refresh the UI.
Related
im trying to add skeleton in my react project i render a gallery images from backend those images are different size (1mb,0.5mb) so the skeleton closed earler in my website thats a problem
and other size photos still not come to front but skeletton stoped to loading skeleton loading
i tried to load gallery images those ah bigger size so i add skeleton but there is some images is low size so skelton stoped after loading small size images
You can create an image component and then use a skeleton inside it.
In this case, if the image is not loaded, the component shows a skeleton. Otherwise, it shows the image. Then you have to map through your images and render the image component.
imageIds.map(id => {
return (
<ImageContainer imageId={id} />
)
})
I assumed you have an API call to get images and a list of image IDs. you can call the API inside the component and check if it is loading, use the skeleton. Otherwise, show the image.
You can implement the logic however you want.
I have a React application that opens a modals conditionally when buttons are pressed. I want a way to access these modals even when they haven't been rendered yet so that I can save the modals as an image in one go using html2canvas. I am able to save the modals as an image individually after I open them but I want to make the process more efficient by saving all the images of the different modals in one go. How can I do this when I have no access to the different modal element IDs since they have not been rendered yet?
This is the current code I have to save the image of the different modals separately after I have opened them:
if (elementId) {
console.log(elementId);
const screenshotTarget = document.getElementById(elementId);
console.log(screenshotTarget);
html2canvas(screenshotTarget, { scale: 0.9 }).then((canvas) => {
canvas.getContext("2d", {
willReadFrequently: true,
});
const base64image = canvas.toDataURL("image/jpeg");
download(base64image, elementId + ".jpeg", "image/jpeg");
});
}
I have considered having all the different modals just load when they are created and then set the display property to none but I don't know if it is inefficient to just render all the modals at once and just hide them. Is there a better option than this?
I fixed this by essentially just rerendering the components I wanted to access when the button was pressed. I found no other way to access the components which are rendered conditionally so this was the only viable solution I could find
I have used Flatlist for showing gallary view of few recent images to select.
I have also added a button to invoke a file picker.
But the issue is to show the button as first item of flatlist I used index===0 in render method which causing the skipping of first image from data.
Whell I tried this.
while setting state which contains the data, I simply added extra element
let data = {
all:[[],...all],
anim:[[],...anim],
still:[[],...still]
}
Now it works. skips the first element of array (means returns the file picker component as item and continue with first image as next item, so first image won't get replaced by file picker)
But it does not look reliable. It won't show folder component until images extracted and set to state. Although I can set this as initial value in state.
But what is the best way to deal with it?
Thanks in advance.
Try ListHeaderComponent as what Doc recommends.
Your best solution here is to pre-define the file picker element as the 0 index of the array and populate the image from the get-go, so it shows immediately and then spread the rest of the data the way that you've done it. There are other stuff that you can try like setting header component, however it will always render above the list, and from the image it seems like your item should be inside the list.
I am using admin-on-rest in my React app and wonder how is possible to make a custom page containing Show (or another detail component) with specified resource Id (for example: I want my app to fetch only resource with id = 1)
I don't know if this is canonical or the intended way to do things but you can supply both basePath and record as props to the ShowButton and EditButton components.
You can use this to redirect your user basically anywhere.
It should be possible (using some switch case or dependent input addon) to also add these props to the ListButton in the Show and Edit view and redirect your user back to the originating ListView.
Here is documentation to supply actions to the List view.
https://marmelab.com/admin-on-rest/List.html#actions
First of all - sorry for my bad English, hope you get my meaning and you will be able to give me an answer.
So, I have the following project structure:
App (Root component) -> Header (included within App) -> Navigation (included within Header).
How should I send data to Navigation (which getting async..)
Now im getting that data in App. then via props send it to Header, and then - render it in Navigation.
I dont want to show Navigation component until the data is loaded.
I dont want Navigation to depend on Header....
At the time - it looks like:
I cant put more then 2 links, that why I just leave here project.
Project (Github)
Actually - it works! But you know, I dont sure that I've select the correct way..
You can just get your component to return null
if (!this.props.data) {
return null;
}
You need to have ViewState stored in reducer to show loader or whatever until data loads or request fails; and you return false or null from render not to show up any markup if you need to.