I am having trouble loading images dynamically in React Native in which the file path is stored in an sqlite database.
Consider 3 buttons: "Show image1", "Show image2", "Show image3"
I could simply use
source={require("./assets/image1.png")}
to load image 1. I could use a require switch statement on all three images to return the require I need depending on the button pressed.
However, I do not know the paths before the application is loaded. I need to retrieve them from the database and cannot do:
var image = imagePathFromDB;
require(image)
The offline database pulls user specified images from an online database from which there can be a very large variation of images so specifying all possible paths ahead of time is not possible.
The application is being developed to work for both Android and iOS.
2 Questions:
Where is an appropriate place to store the image files
..and more importantly
How do I retrieve and render them dynamically?
in React native ,all your images sources needs to be loaded before compiling your bundle.
you can use dynamic images by using switch case
Like
class App extends Component {
state = { avatar: "" }
get avatarImage() {
switch (this.state.avatar) {
case "car":
return require('./car.png');
case "bike":
return require('./bike.png');
case "bus":
return require('./bus.png');
default:
return require('./defualt.png');
}
}
render() {
return <Image source={this.avatarImage} />
}
}
place your images in case and then store only case value for specific output
Related
I have an Image file that i create during runtime.
I want to set it as backgroundImage of a ContentPage (in android project)
I tried to set the path of the file to the BackgroundImage property but it doesn't work.
Is there a way to do it ?
I can't put it as resource since I create it at runtime
Put your page into Grid which first element is an Image, then set that image Source to your stream like:
Image bgImage = new Image
{
Source = ImageSource.FromStream(() => { return new MemoryStream(buffer); });
}
Grid mainGrid = new Grid
{
Children = {bgImage,yourContent}
};
yourPage.Content= mainGrid;
I think that documentation is out of date. Becuase target Android has more than one resources.
as
/drawable-hdpi
/drawable-xhdpi
etc.
So you should add your images for all folders because it will work device. It Works.
*but I think that main issue on Xamarin.Forms
Becase drawable folder have to default images source when system couldn't find special resolution must select from default folder... *
I am using knockout js in my single page application. I have a file upload input tag that I'm using knockout to upload the file with. In this case the files being uploaded are images.
Once the image has been processed by my ASP.NET Web API, and it comes back into my callback function I am inserting the response into an observable array which inhand updates the screen with the new image and text that was added.
However, for some reason the images aren't being displayed. If I refresh the page it loads the images fine but when adding to the observable array it's not showing the images.
Any ideas?
Edit: Here is my code that adds the item, it's pretty straight forward.
item = {
"insightTypeId": 0,
"memberId": currentMemberId(),
"postedByMemberId": store.fetch("currentUser"),
"value": insight(),
"image": "content/insights/" + fileName
};
messaging.client.addItem = function(item) {
member().insights.unshift(item);
};
Update
Forgot to mention that it works fine on a computer viewing the site, but on a phone it doesn't work.
I figured out that it was a mobile safari resource issue
Publishing a component which has multiple dynamic templates will usually result in all the possible dynamic component presentations being published to the broker.
When you create a DCT with the option to place the item on a page, a content editor may not want to publish the components directly, simply relying on the Page publish to do the right thing. We could consider three possible desired publishing scenarios:
That publishing the page should only cause the static component presentations to be rendered, (plus whatever CD code is necessary to display the dynamic ones)
That in addition to static CPs, any dynamic CPs should be published. Other possible dynamic renderings of the same component are not published.
If a dynamic CP is published, the usual component publishing semantics are followed,
and all dynamic renderings will go to the broker.
Tridion's default behaviour appears to be scenario 2), whereas my experience is that often what you want is scenario 3), giving you a complete and
consistent view of any given component on the CD side.
What is the best way to implement scenario 3 (including getting unpublish to work correctly)?
In my opinion, the best answer for your question is to implement a custom Resolver that would include the required Dynamic Component Presentations. I would be wary of doing anything when unpublishing, as sometimes you may want to keep the DCPs after unpublishing a given page (for "latest news" type of functionality or any other sort of dynamic queries), but the code sample below would make it simple for you to adapt if you need to unpublish all DCPs.
Warning: Below code is not production-tested.
using Tridion.ContentManager;
using Tridion.ContentManager.CommunicationManagement;
using Tridion.ContentManager.ContentManagement;
using Tridion.ContentManager.Publishing;
using Tridion.ContentManager.Publishing.Resolving;
public class IncludeDynamicComponentPresentations : IResolver
{
public void Resolve(
IdentifiableObject item,
ResolveInstruction instruction,
PublishContext context,
Tridion.Collections.ISet<ResolvedItem> resolvedItems)
{
if (!(instruction.Purpose == ResolvePurpose.Publish ||
instruction.Purpose == ResolvePurpose.RePublish))
{
// Do nothing more when unpublishing
return;
}
Session session = item.Session;
foreach (ResolvedItem resolvedItem in resolvedItems)
{
// Only do something if we're dealing with a page
if (!(resolvedItem.Item is Page)) continue;
Page page = (Page)resolvedItem.Item;
if (page.ComponentPresentations.Count > 0)
{
UsingItemsFilter filter = new UsingItemsFilter(session);
filter.InRepository = page.ContextRepository;
filter.ItemTypes = new[] { ItemType.ComponentTemplate };
foreach (ComponentPresentation cp in page.ComponentPresentations)
{
// Find all component templates linked to this component's schema
Schema schema = cp.Component.Schema;
foreach (ComponentTemplate ct in schema.GetUsingItems(filter))
{
if (!ct.Id.Equals(cp.ComponentTemplate.Id))
{
if (ct.IsRepositoryPublishable)
{
resolvedItems.Add(new ResolvedItem(cp.Component, ct));
}
}
}
}
}
}
}
}
You would now need to add this to the GAC and modify [Tridion]\Config\Tridion.ContentManager.Config so this Resolver is called after every resolve action (under resolving/mappings for every item type).
Perhaps a Custom Resolver would help in this situation? This would give you access to all the items the result from a publish action, allowing you to change the default behaviour.
There's a good example of this in the SDL Tridion documentation portal, but it basically allows you to create a custom resolver class in .net, where you can implement your custom logic.
I have created a simple SWF-loader in ActionScript 3.0. It loads an SWF from a server and then plays it. While downloading, it displays the "loading" screen.
Its main defect is that it can load only one Flash application - the one which it is compiled for. Let's say it's named test1.swf.
Is there any way to make the loader support more than one Flash app (for example test2.swf and test3.swf)? I mean by passing external parameters to it and not by creating another loader. Is using Javascript the only way to do it? I don't want my loader to require the Javascript support.
And I really don't want to create separate loaders for all of my apps...
Thanks in advance.
In order to load an external SWF your loader only need the url of the swf to be loaded, this url doesn't have to be hardcoded. There are many ways to pass parameters to a SWF file and they don't necessarily require Javascript.
You could load a XML file for instance, a simple text file would work too , you could also use a PHP script. Using flahsvars would require Javascript, although only to set your application in your HTML page.
With the following example , your app doesn't need to recompile , you simply change the url in the text file.
Example with a text file containing a url, something like this:
http://yourwebsite.com/test1.swf
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE , completeHandler );
urlLoader.load( new URLRequest('swfURL.txt') );
function completeHandler(event:Event):void
{
loadExternalSWF(event.target.data );
event.target.removeEventListener(Event.COMPLETE , completeHandler );
}
function loadExternalSWF(url:String ):void
{
//your code here , using the url value
trace(url );//should return your text file content
}
I'm building a Flex widget for a private vBulletin site, and the Flex widget needs to access an XML file on the vBulletin server in order to display data.
For security reasons, the XML URL will need to have the value in the bbsessionhash cookie passed along in the URL request from Flex. The Flex widget will be embedded in the private area that the user has logged into, so the Flex request will be coming from the same website the cookie is from.
Is there any way to access the cookies directly within Flex? I would prefer not to use ExternalInterface to grab the cookie data from JavaScript, as it could get a little messy (the templates are developed by a completely different dev team).
I have never tried this, but this library might just do the trick.
As per the flash or flex cookies are concern developer can use shared object which is one kind of cookie used for flex application.
The sample code snippet is as followes
import flash.net.SharedObject;
// get/create the shared object with a unique name.
// If the shared object exists this grab it, if not
// then it will create a new one
var so: SharedObject = SharedObject.getLocal("UniqueName");
// the shared object has a propery named data, it's
// an object on which you can create, read, or modify
// properties (you can't set the data property itself!)
// you can check to see if it already has something set
// using hasOwnProperty, so we'll check if it has a var
// use it if it does, or set it to a default if it doesn't
if (so.data.hasOwnProperty("theProp"))
{
trace("already has data! It reads: " + so.data.theProp);
}
else
{
so.data.theProp = "default value";
so.flush(); // flush saves the data
trace("It didn't have a value, so we set it.");
}
Accessing Flex SharedObject is NOT the same as accessing the Browser cookies, to access the browser cookies, you may use the ExternalInterface class, please check the following reference to see samples:
http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_4.html
A reference of how to use and control cookies using JavaScript can be found here:
http://www.quirksmode.org/js/cookies.html
I would use the following Flex code:
var myCookie:String = ExternalInterface.call("getCookie('cookieName')");
And in the HTML I would add the following Javascript:
function getCookie(c_name) {
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++) {
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name) return unescape(y);
}
}
If you require more help you could also check the Flex documentation.